+
+
+bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
+{
+ // if we are in a locking inset we should try to insert the
+ // inset there otherwise this is a illegal function now
+ if (bv_->theLockingInset()) {
+ if (bv_->theLockingInset()->InsertInsetAllowed(inset))
+ return bv_->theLockingInset()->InsertInset(bv_, inset);
+ return false;
+ }
+
+ // not quite sure if we want this...
+ bv_->text->SetCursorParUndo(buffer_);
+ bv_->text->FreezeUndo();
+
+ beforeChange(bv_->text);
+ if (!lout.empty()) {
+ update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
+ bv_->text->BreakParagraph(bv_);
+ update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
+
+ if (bv_->text->cursor.par()->size()) {
+ bv_->text->CursorLeft(bv_);
+
+ bv_->text->BreakParagraph(bv_);
+ update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
+ }
+
+ pair<bool, LyXTextClass::size_type> lres =
+ textclasslist.NumberOfLayout(buffer_->params
+ .textclass, lout);
+ LyXTextClass::size_type lay;
+ if (lres.first != false) {
+ // layout found
+ lay = lres.second;
+ } else {
+ // layout not fount using default "Standard" (0)
+ lay = 0;
+ }
+
+ bv_->text->SetLayout(bv_, lay);
+
+ bv_->text->SetParagraph(bv_, 0, 0,
+ 0, 0,
+ VSpace(VSpace::NONE), VSpace(VSpace::NONE),
+ LYX_ALIGN_LAYOUT,
+ string(),
+ 0);
+ update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
+
+ bv_->text->current_font.setLatex(LyXFont::OFF);
+ }
+
+ bv_->text->InsertInset(bv_, inset);
+ update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
+
+ bv_->text->UnFreezeUndo();
+ return true;
+}
+
+
+void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
+{
+ if (!inset)
+ return;
+
+ // first check for locking insets
+ if (bv_->theLockingInset()) {
+ if (bv_->theLockingInset() == inset) {
+ if (bv_->text->UpdateInset(bv_, inset)) {
+ update();
+ if (mark_dirty) {
+ buffer_->markDirty();
+ }
+ updateScrollbar();
+ return;
+ }
+ } else if (bv_->theLockingInset()->UpdateInsetInInset(bv_, inset)) {
+ if (bv_->text->UpdateInset(bv_,
+ bv_->theLockingInset())) {
+ update();
+ if (mark_dirty){
+ buffer_->markDirty();
+ }
+ updateScrollbar();
+ return;
+ }
+ }
+ }
+
+ // then check the current buffer
+ if (available()) {
+ hideCursor();
+ update(bv_->text, BufferView::UPDATE);
+ if (bv_->text->UpdateInset(bv_, inset)) {
+ if (mark_dirty) {
+ update(bv_->text,
+ BufferView::SELECT
+ | BufferView::FITCUR
+ | BufferView::CHANGE);
+ } else {
+ update(bv_->text, SELECT);
+ }
+ return;
+ }
+ }
+}
+
+
+void BufferView::Pimpl::gotoInset(vector<Inset::Code> const & codes,
+ bool same_content)
+{
+ if (!available()) return;
+
+ hideCursor();
+ beforeChange(bv_->text);
+ update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
+
+ string contents;
+ if (same_content &&
+ bv_->text->cursor.par()->GetChar(bv_->text->cursor.pos()) == LyXParagraph::META_INSET) {
+ Inset const * inset = bv_->text->cursor.par()->GetInset(bv_->text->cursor.pos());
+ if (find(codes.begin(), codes.end(), inset->LyxCode())
+ != codes.end())
+ contents =
+ static_cast<InsetCommand const *>(inset)->getContents();
+ }
+
+ if (!bv_->text->GotoNextInset(bv_, codes, contents)) {
+ if (bv_->text->cursor.pos()
+ || bv_->text->cursor.par() != bv_->text->FirstParagraph()) {
+ LyXCursor tmp = bv_->text->cursor;
+ bv_->text->cursor.par(bv_->text->FirstParagraph());
+ bv_->text->cursor.pos(0);
+ if (!bv_->text->GotoNextInset(bv_, codes, contents)) {
+ bv_->text->cursor = tmp;
+ bv_->owner()->message(_("No more insets"));
+ }
+ } else {
+ bv_->owner()->message(_("No more insets"));
+ }
+ }
+ update(bv_->text, BufferView::SELECT|BufferView::FITCUR);
+ bv_->text->selection.cursor = bv_->text->cursor;
+}
+
+
+void BufferView::Pimpl::gotoInset(Inset::Code code, bool same_content)
+{
+ gotoInset(vector<Inset::Code>(1, code), same_content);
+}