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 = bv_->getLyXText()->selectionAsString(*bv_->buffer(), 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();
583 // The visible LyXView need a resize
584 resizeCurrentBuffer();
588 if (widthChange || heightChange)
591 // always make sure that the scrollbar is sane.
593 owner_->updateLayoutChoice();
597 void BufferView::Pimpl::update()
599 //lyxerr << "BufferView::update()" << endl;
600 // fix cursor coordinate cache in case something went wrong
602 // check needed to survive LyX startup
603 if (bv_->getLyXText()) {
604 // update all 'visible' paragraphs
605 ParagraphList::iterator beg;
606 ParagraphList::iterator end;
607 getParsInRange(buffer_->paragraphs(),
608 top_y(), top_y() + workarea().workHeight(),
610 bv_->text()->redoParagraphs(beg, end);
613 screen().redraw(*bv_);
617 // Callback for cursor timer
618 void BufferView::Pimpl::cursorToggle()
621 cursor_timeout.restart();
625 screen().toggleCursor(*bv_);
626 cursor_timeout.restart();
630 bool BufferView::Pimpl::available() const
632 return buffer_ && bv_->text();
636 Change const BufferView::Pimpl::getCurrentChange()
638 if (!bv_->buffer()->params().tracking_changes)
639 return Change(Change::UNCHANGED);
641 LyXText * text = bv_->getLyXText();
642 LCursor & cur = bv_->cursor();
644 if (!cur.selection())
645 return Change(Change::UNCHANGED);
647 return text->getPar(cur.selBegin())
648 ->lookupChangeFull(cur.selBegin().pos());
652 void BufferView::Pimpl::savePosition(unsigned int i)
654 if (i >= saved_positions_num)
656 saved_positions[i] = Position(buffer_->fileName(),
657 bv_->text()->cursorPar()->id(),
658 bv_->text()->cursor().pos());
660 owner_->message(bformat(_("Saved bookmark %1$s"), tostr(i)));
664 void BufferView::Pimpl::restorePosition(unsigned int i)
666 if (i >= saved_positions_num)
669 string const fname = saved_positions[i].filename;
671 bv_->cursor().clearSelection();
673 if (fname != buffer_->fileName()) {
675 if (bufferlist.exists(fname))
676 b = bufferlist.getBuffer(fname);
678 b = bufferlist.newBuffer(fname);
679 ::loadLyXFile(b, fname); // don't ask, just load it
685 ParIterator par = buffer_->getParFromID(saved_positions[i].par_id);
686 if (par == buffer_->par_iterator_end())
689 bv_->text()->setCursor(par.pit(),
690 min(par->size(), saved_positions[i].par_pos));
693 owner_->message(bformat(_("Moved to bookmark %1$s"), tostr(i)));
697 bool BufferView::Pimpl::isSavedPosition(unsigned int i)
699 return i < saved_positions_num && !saved_positions[i].filename.empty();
703 void BufferView::Pimpl::switchKeyMap()
705 if (!lyxrc.rtl_support)
708 Intl & intl = owner_->getIntl();
709 if (bv_->getLyXText()->real_current_font.isRightToLeft()) {
710 if (intl.keymap == Intl::PRIMARY)
713 if (intl.keymap == Intl::SECONDARY)
719 void BufferView::Pimpl::center()
721 LyXText * text = bv_->text();
723 bv_->cursor().clearSelection();
724 int const half_height = workarea().workHeight() / 2;
725 int new_y = text->cursorY(bv_->cursor().cursor_.front()) - half_height;
729 // FIXME: look at this comment again ...
730 // This updates top_y() but means the fitCursor() call
731 // from the update(FITCUR) doesn't realise that we might
732 // have moved (e.g. from GOTOPARAGRAPH), so doesn't cause
733 // the scrollbar to be updated as it should, so we have
734 // to do it manually. Any operation that does a center()
735 // and also might have moved top_y() must make sure to call
736 // updateScrollbar() currently. Never mind that this is a
737 // pretty obfuscated way of updating text->top_y()
742 void BufferView::Pimpl::stuffClipboard(string const & stuff) const
744 workarea().putClipboard(stuff);
748 InsetBase * BufferView::Pimpl::getInsetByCode(InsetBase::Code code)
751 CursorSlice cursor = bv_->getLyXText()->cursor;
752 Buffer::inset_iterator it =
753 find_if(Buffer::inset_iterator(
754 cursorPar(), cursor().pos()),
755 buffer_->inset_iterator_end(),
756 lyx::compare_memfun(&Inset::lyxCode, code));
757 return it != buffer_->inset_iterator_end() ? (*it) : 0;
759 // Ok, this is a little bit too brute force but it
760 // should work for now. Better infrastructure is coming. (Lgb)
762 Buffer * b = bv_->buffer();
763 LyXText * text = bv_->getLyXText();
765 Buffer::inset_iterator beg = b->inset_iterator_begin();
766 Buffer::inset_iterator end = b->inset_iterator_end();
768 bool cursor_par_seen = false;
770 for (; beg != end; ++beg) {
771 if (beg.getPar() == text->cursorPar()) {
772 cursor_par_seen = true;
774 if (cursor_par_seen) {
775 if (beg.getPar() == text->cursorPar()
776 && beg.getPos() >= text->cursor().pos()) {
779 if (beg.getPar() != text->cursorPar()) {
786 // Now find the first inset that matches code.
787 for (; beg != end; ++beg) {
788 if (beg->lyxCode() == code)
797 void BufferView::Pimpl::MenuInsertLyXFile(string const & filenm)
799 string filename = filenm;
801 if (filename.empty()) {
802 // Launch a file browser
803 string initpath = lyxrc.document_path;
806 string const trypath = owner_->buffer()->filePath();
807 // If directory is writeable, use this as default.
808 if (IsDirWriteable(trypath))
812 FileDialog fileDlg(_("Select LyX document to insert"),
814 make_pair(string(_("Documents|#o#O")),
815 string(lyxrc.document_path)),
816 make_pair(string(_("Examples|#E#e")),
817 string(AddPath(system_lyxdir(), "examples"))));
819 FileDialog::Result result =
820 fileDlg.open(initpath,
821 FileFilterList(_("LyX Documents (*.lyx)")),
824 if (result.first == FileDialog::Later)
827 filename = result.second;
829 // check selected filename
830 if (filename.empty()) {
831 owner_->message(_("Canceled."));
836 // get absolute path of file and add ".lyx" to the filename if
838 filename = FileSearch(string(), filename, "lyx");
840 string const disp_fn = MakeDisplayPath(filename);
841 owner_->message(bformat(_("Inserting document %1$s..."), disp_fn));
842 if (bv_->insertLyXFile(filename))
843 owner_->message(bformat(_("Document %1$s inserted."),
846 owner_->message(bformat(_("Could not insert document %1$s"),
851 void BufferView::Pimpl::trackChanges()
853 Buffer * buf = bv_->buffer();
854 bool const tracking(buf->params().tracking_changes);
857 ParIterator const end = buf->par_iterator_end();
858 for (ParIterator it = buf->par_iterator_begin(); it != end; ++it)
860 buf->params().tracking_changes = true;
862 // we cannot allow undos beyond the freeze point
863 buf->undostack().clear();
866 bv_->text()->setCursor(0, 0);
867 #warning changes FIXME
868 bool found = lyx::find::findNextChange(bv_);
870 owner_->getDialogs().show("changes");
874 ParIterator const end = buf->par_iterator_end();
875 for (ParIterator it = buf->par_iterator_begin(); it != end; ++it)
876 it->untrackChanges();
877 buf->params().tracking_changes = false;
880 buf->redostack().clear();
884 bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd0)
887 // this is only called for mouse related events.
889 FuncRequest cmd = cmd0;
890 cmd.y += bv_->top_y();
891 lyxerr << "*** workAreaDispatch: request: " << cmd << std::endl;
893 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()) {
915 case LFUN_MOUSE_MOTION:
916 case LFUN_MOUSE_PRESS:
917 case LFUN_MOUSE_RELEASE:
918 case LFUN_MOUSE_DOUBLE:
919 case LFUN_MOUSE_TRIPLE: {
920 // We pass those directly to the Bufferview, since
921 // otherwise selection handling breaks down
923 // Doesn't go through lyxfunc, so we need to update
924 // the layout choice etc. ourselves
926 // e.g. Qt mouse press when no buffer
930 screen().hideCursor();
932 // either the inset under the cursor or the
933 // surrounding LyXText will handle this event.
935 // built temporary path to inset
936 LyXText * text = bv_->text();
937 InsetBase * const inset_hit = text->checkInsetHit(cmd.x, cmd.y);
939 inset_hit->edit(cur, cmd.x, cmd.y);
941 text->setCursorFromCoordinates(cur.current(), cmd.x, cmd.y);
942 lyxerr << "created temp cursor: " << cur << endl;
944 // Dispatch to the temp cursor.
945 // An inset (or LyXText) can assign this to bv->cursor()
946 // if it wishes to do so.
947 DispatchResult res = cur.dispatch(cmd);
949 if (fitCursor() || res.update())
952 // see workAreaKeyPress
953 cursor_timeout.restart();
954 screen().showCursor(*bv_);
956 // skip these when selecting
957 if (cmd.action != LFUN_MOUSE_MOTION) {
958 owner_->updateLayoutChoice();
959 owner_->updateToolbar();
962 // slight hack: this is only called currently when we
963 // clicked somewhere, so we force through the display
964 // of the new status here.
965 owner_->clearMessage();
970 lyxerr << "*** UNDISPATCHED: " << cmd;
971 //owner_->dispatch(cmd);
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) {
994 case LFUN_SCROLL_INSET:
995 // this is not handled here as this function is only active
996 // if we have a locking_inset and that one is (or contains)
1000 case LFUN_FILE_INSERT:
1001 MenuInsertLyXFile(cmd.argument);
1004 case LFUN_FILE_INSERT_ASCII_PARA:
1005 InsertAsciiFile(bv_, cmd.argument, true);
1008 case LFUN_FILE_INSERT_ASCII:
1009 InsertAsciiFile(bv_, cmd.argument, false);
1012 case LFUN_FONT_STATE:
1013 owner_->getLyXFunc().setMessage(currentState(bv_));
1016 case LFUN_INSERT_LABEL: {
1017 // Try and generate a valid label
1018 string const contents = cmd.argument.empty() ?
1019 getPossibleLabel(*bv_) : cmd.argument;
1020 InsetCommandParams icp("label", contents);
1021 string data = InsetCommandMailer::params2string("label", icp);
1022 owner_->getDialogs().show("label", data, 0);
1026 case LFUN_BOOKMARK_SAVE:
1027 savePosition(strToUnsignedInt(cmd.argument));
1030 case LFUN_BOOKMARK_GOTO:
1031 restorePosition(strToUnsignedInt(cmd.argument));
1034 case LFUN_REF_GOTO: {
1035 string label = cmd.argument;
1036 if (label.empty()) {
1038 static_cast<InsetRef*>(getInsetByCode(InsetBase::REF_CODE));
1040 label = inset->getContents();
1046 bv_->gotoLabel(label);
1050 // --- accented characters ---------------------------
1053 case LFUN_CIRCUMFLEX:
1063 case LFUN_SPECIAL_CARON:
1066 case LFUN_HUNG_UMLAUT:
1069 if (cmd.argument.empty()) {
1071 owner_->getLyXFunc().handleKeyFunc(cmd.action);
1073 owner_->getLyXFunc().handleKeyFunc(cmd.action);
1074 owner_->getIntl().getTransManager()
1075 .TranslateAndInsert(cmd.argument[0], bv_->getLyXText());
1080 case LFUN_FLOAT_LIST:
1081 if (tclass.floats().typeExist(cmd.argument)) {
1082 InsetBase * inset = new InsetFloatList(cmd.argument);
1083 bv_->insertInset(inset, tclass.defaultLayoutName());
1085 lyxerr << "Non-existent float type: "
1086 << cmd.argument << endl;
1090 case LFUN_LAYOUT_PARAGRAPH: {
1092 params2string(*bv_->getLyXText()->cursorPar(), data);
1093 data = "show\n" + data;
1094 bv_->owner()->getDialogs().show("paragraph", data);
1098 case LFUN_PARAGRAPH_UPDATE:
1099 updateParagraphDialog();
1102 case LFUN_PARAGRAPH_APPLY:
1103 setParagraphParams(*bv_, cmd.argument);
1106 case LFUN_THESAURUS_ENTRY: {
1107 string arg = cmd.argument;
1110 arg = bv_->getLyXText()->selectionAsString(*buffer_,
1114 if (arg.size() > 100 || arg.empty()) {
1115 // Get word or selection
1116 bv_->getLyXText()->selectWordWhenUnderCursor(lyx::WHOLE_WORD);
1117 arg = bv_->getLyXText()->selectionAsString(*buffer_, false);
1118 // FIXME: where is getLyXText()->unselect(bv_) ?
1122 bv_->owner()->getDialogs().show("thesaurus", arg);
1126 case LFUN_TRACK_CHANGES:
1130 case LFUN_MERGE_CHANGES:
1131 owner_->getDialogs().show("changes");
1134 case LFUN_ACCEPT_ALL_CHANGES: {
1135 bv_->text()->setCursor(0, 0);
1136 #warning FIXME changes
1137 while (lyx::find::findNextChange(bv_))
1138 bv_->getLyXText()->acceptChange();
1143 case LFUN_REJECT_ALL_CHANGES: {
1144 bv_->text()->setCursor(0, 0);
1145 #warning FIXME changes
1146 while (lyx::find::findNextChange(bv_))
1147 bv_->getLyXText()->rejectChange();
1152 case LFUN_ACCEPT_CHANGE: {
1153 bv_->getLyXText()->acceptChange();
1158 case LFUN_REJECT_CHANGE: {
1159 bv_->getLyXText()->rejectChange();
1164 case LFUN_WORD_FIND:
1165 lyx::find::find(bv_, cmd);
1168 case LFUN_WORD_REPLACE:
1169 lyx::find::replace(bv_, cmd);
1173 cur.clearSelection();
1176 cur.message(N_("Mark off"));
1180 cur.clearSelection();
1184 cur.message(N_("Mark on"));
1188 cur.clearSelection();
1190 cur.message(N_("Mark removed"));
1193 cur.message(N_("Mark set"));
1199 case LFUN_UNKNOWN_ACTION:
1200 cur.errorMessage(N_("Unknown function!"));
1211 bool BufferView::Pimpl::ChangeInsets(InsetBase::Code code,
1212 string const & from, string const & to)
1214 bool need_update = false;
1215 CursorSlice cur = bv_->text()->cursor();
1217 ParIterator end = bv_->buffer()->par_iterator_end();
1218 for (ParIterator it = bv_->buffer()->par_iterator_begin();
1220 bool changed_inset = false;
1221 for (InsetList::iterator it2 = it->insetlist.begin();
1222 it2 != it->insetlist.end(); ++it2) {
1223 if (it2->inset->lyxCode() == code) {
1224 InsetCommand * inset = static_cast<InsetCommand *>(it2->inset);
1225 if (inset->getContents() == from) {
1226 inset->setContents(to);
1227 changed_inset = true;
1231 if (changed_inset) {
1236 // The test it.size() == 1 was needed to prevent crashes.
1237 // How to set the cursor correctly when it.size() > 1 ??
1238 if (it.size() == 1) {
1239 bv_->text()->setCursorIntern(bv_->text()->parOffset(it.pit()), 0);
1240 bv_->text()->redoParagraph(bv_->text()->cursorPar());
1244 bv_->text()->setCursorIntern(cur.par(), cur.pos());
1249 void BufferView::Pimpl::updateParagraphDialog()
1251 if (!bv_->owner()->getDialogs().visible("paragraph"))
1253 CursorSlice const & cur = bv_->cursor().innerTextSlice();
1254 LyXText * text = bv_->cursor().innerText();
1255 Paragraph const & par = *text->getPar(cur.par());
1257 params2string(par, data);
1259 // Will the paragraph accept changes from the dialog?
1260 InsetBase * const inset = cur.inset();
1262 !(inset && inset->forceDefaultParagraphs(inset));
1264 data = "update " + tostr(accept) + '\n' + data;
1265 bv_->owner()->getDialogs().update("paragraph", data);