-
-
-bool BufferView::Pimpl::insertInset(InsetBase * inset, string const & lout)
-{
- // not quite sure if we want this...
- bv_->text()->recUndo(bv_->text()->cursor().par());
- freezeUndo();
-
- bv_->cursor().clearSelection();
- if (!lout.empty()) {
- bv_->text()->breakParagraph(bv_->buffer()->paragraphs());
-
- if (!bv_->text()->cursorPar()->empty()) {
- bv_->text()->cursorLeft(bv_);
- bv_->text()->breakParagraph(bv_->buffer()->paragraphs());
- }
-
- string lres = lout;
- LyXTextClass const & tclass = buffer_->params().getLyXTextClass();
- bool hasLayout = tclass.hasLayout(lres);
-
- bv_->text()->setLayout(hasLayout ? lres : tclass.defaultLayoutName());
- bv_->text()->setParagraph(Spacing(), LYX_ALIGN_LAYOUT, string(), 0);
- }
- bv_->cursor().innerText()->insertInset(inset);
- unFreezeUndo();
- return true;
-}
-
-
-bool BufferView::Pimpl::ChangeInsets(InsetBase::Code code,
- string const & from, string const & to)
-{
- bool need_update = false;
- CursorSlice cur = bv_->text()->cursor();
-
- ParIterator end = bv_->buffer()->par_iterator_end();
- for (ParIterator it = bv_->buffer()->par_iterator_begin();
- it != end; ++it) {
- bool changed_inset = false;
- for (InsetList::iterator it2 = it->insetlist.begin();
- it2 != it->insetlist.end(); ++it2) {
- if (it2->inset->lyxCode() == code) {
- InsetCommand * inset = static_cast<InsetCommand *>(it2->inset);
- if (inset->getContents() == from) {
- inset->setContents(to);
- changed_inset = true;
- }
- }
- }
- if (changed_inset) {
- need_update = true;
-
- // FIXME
-
- // The test it.size() == 1 was needed to prevent crashes.
- // How to set the cursor correctly when it.size() > 1 ??
- if (it.size() == 1) {
- bv_->text()->setCursorIntern(bv_->text()->parOffset(it.pit()), 0);
- bv_->text()->redoParagraph(bv_->text()->cursorPar());
- }
- }
- }
- bv_->text()->setCursorIntern(cur.par(), cur.pos());
- return need_update;
-}
-
-
-void BufferView::Pimpl::updateParagraphDialog()
-{
- if (!bv_->owner()->getDialogs().visible("paragraph"))
- return;
- CursorSlice const & cur = bv_->cursor().innerTextSlice();
- LyXText * text = bv_->cursor().innerText();
- Paragraph const & par = *text->getPar(cur.par());
- string data;
- params2string(par, data);
-
- // Will the paragraph accept changes from the dialog?
- InsetBase * const inset = cur.inset();
- bool const accept =
- !(inset && inset->forceDefaultParagraphs(inset));
-
- data = "update " + tostr(accept) + '\n' + data;
- bv_->owner()->getDialogs().update("paragraph", data);
-}