diff --git a/src/BufferView.C b/src/BufferView.C index d1ff326a34..6c7b71e859 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -18,6 +18,7 @@ #include "buffer.h" #include "bufferlist.h" +#include "bufferparams.h" #include "BufferView_pimpl.h" #include "debug.h" #include "funcrequest.h" @@ -26,6 +27,7 @@ #include "language.h" #include "lyxlayout.h" #include "lyxtext.h" +#include "lyxtextclass.h" #include "paragraph.h" #include "paragraph_funcs.h" #include "PosIterator.h" @@ -301,9 +303,30 @@ void BufferView::setCursorFromRow(int row) } -bool BufferView::insertInset(InsetBase * inset, string const & lout) +void BufferView::insertInset(InsetBase * inset, string const & lout) { - return pimpl_->insertInset(inset, lout); + // not quite sure if we want this... + text()->recUndo(text()->cursor().par()); + freezeUndo(); + + cursor().clearSelection(); + if (!lout.empty()) { + text()->breakParagraph(buffer()->paragraphs()); + + if (!text()->cursorPar()->empty()) { + text()->cursorLeft(true); + text()->breakParagraph(buffer()->paragraphs()); + } + + string lres = lout; + LyXTextClass const & tclass = buffer()->params().getLyXTextClass(); + bool hasLayout = tclass.hasLayout(lres); + + text()->setLayout(hasLayout ? lres : tclass.defaultLayoutName()); + text()->setParagraph(Spacing(), LYX_ALIGN_LAYOUT, string(), 0); + } + cursor().innerText()->insertInset(inset); + unFreezeUndo(); } diff --git a/src/BufferView.h b/src/BufferView.h index fa89ca527c..b047df3904 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -140,11 +140,9 @@ public: /// set the cursor based on the given TeX source row void setCursorFromRow(int row); - /** - * Insert an inset into the buffer. - * Place it in a layout of lout, - */ - bool insertInset(InsetBase * inset, std::string const & lout = std::string()); + /// Insert an inset into the buffer, in a layout of lout. + void insertInset(InsetBase * inset, + std::string const & lout = std::string()); /// Inserts a lyx file at cursor position. return false if it fails bool insertLyXFile(std::string const & file); diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index 2f136433d3..d67b7990cc 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -1077,20 +1077,10 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & cmd) } break; - case LFUN_INSET_INSERT: { - // Same as above. - BOOST_ASSERT(false); - InsetBase * inset = createInset(bv_, cmd); - if (!inset || !insertInset(inset)) - delete inset; - break; - } - case LFUN_FLOAT_LIST: if (tclass.floats().typeExist(cmd.argument)) { InsetBase * inset = new InsetFloatList(cmd.argument); - if (!insertInset(inset, tclass.defaultLayoutName())) - delete inset; + bv_->insertInset(inset, tclass.defaultLayoutName()); } else { lyxerr << "Non-existent float type: " << cmd.argument << endl; @@ -1218,34 +1208,6 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & cmd) } -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) { diff --git a/src/BufferView_pimpl.h b/src/BufferView_pimpl.h index 9880aabe7b..308e991f53 100644 --- a/src/BufferView_pimpl.h +++ b/src/BufferView_pimpl.h @@ -101,8 +101,6 @@ struct BufferView::Pimpl : public boost::signals::trackable { void switchKeyMap(); /// void center(); - /// - bool insertInset(InsetBase * inset, std::string const & lout = std::string()); /// a function should be executed from the workarea bool workAreaDispatch(FuncRequest const & ev); /// a function should be executed diff --git a/src/ChangeLog b/src/ChangeLog index 720cb35123..c00d227cfc 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,4 +1,12 @@ +2004-02-04 André Pönitz + + * BufferView.[Ch] (insertInset): + * BufferView_pimpl.[Ch] (insertInset): remove unneeded return value + + * text2.C: + * text3.C: adjust + 2004-02-03 Alfredo Braunstein * BufferView_pimpl.C (dispatch): remove call to LCursor::dispatch diff --git a/src/mathed/math_hullinset.C b/src/mathed/math_hullinset.C index 11d53bbdca..165e6b0a3f 100644 --- a/src/mathed/math_hullinset.C +++ b/src/mathed/math_hullinset.C @@ -1328,10 +1328,7 @@ namespace { bool openNewInset(LCursor & cur, InsetBase * inset) { - if (!cur.bv().insertInset(inset)) { - delete inset; - return false; - } + cur.bv().insertInset(inset); inset->edit(cur, true); return true; } diff --git a/src/text2.C b/src/text2.C index e15775524e..a352a9b05e 100644 --- a/src/text2.C +++ b/src/text2.C @@ -291,11 +291,9 @@ void LyXText::setLayout(string const & layout) bv()->owner()->dispatch(FuncRequest(LFUN_ENDSEL)); bv()->owner()->dispatch(FuncRequest(LFUN_CUT)); InsetBase * inset = new InsetEnvironment(params, layout); - if (bv()->insertInset(inset)) { - //inset->edit(bv()); - //bv()->owner()->dispatch(FuncRequest(LFUN_PASTE)); - } else - delete inset; + bv()->insertInset(inset); + //inset->edit(bv()); + //bv()->owner()->dispatch(FuncRequest(LFUN_PASTE)); return; } diff --git a/src/text3.C b/src/text3.C index ca40002a96..778ba44459 100644 --- a/src/text3.C +++ b/src/text3.C @@ -400,10 +400,8 @@ void specialChar(LyXText * text, BufferView * bv, InsetSpecialChar::Kind kind) bv->update(); InsetSpecialChar * new_inset = new InsetSpecialChar(kind); replaceSelection(text); - if (!bv->insertInset(new_inset)) - delete new_inset; - else - bv->update(); + bv->insertInset(new_inset); + bv->update(); } @@ -419,14 +417,11 @@ void doInsertInset(BufferView * bv, FuncRequest const & cmd, bv->owner()->dispatch(FuncRequest(LFUN_CUT)); gotsel = true; } - if (bv->insertInset(inset)) { - if (edit) - inset->edit(bv->cursor(), true); - if (gotsel && pastesel) - bv->owner()->dispatch(FuncRequest(LFUN_PASTE)); - } else { - delete inset; - } + bv->insertInset(inset); + if (edit) + inset->edit(bv->cursor(), true); + if (gotsel && pastesel) + bv->owner()->dispatch(FuncRequest(LFUN_PASTE)); } } // anon namespace @@ -867,8 +862,8 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd) case LFUN_INSET_INSERT: { InsetBase * inset = createInset(bv, cmd); - if (inset && !bv->insertInset(inset)) - delete inset; + if (inset) + bv->insertInset(inset); break; } @@ -1112,8 +1107,9 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd) BufferParams const & bufparams = bv->buffer()->params(); if (style->pass_thru || - pit->getFontSettings(bufparams,pos).language()->lang() == "hebrew" || - !bv->insertInset(new InsetQuotes(c, bufparams))) + pit->getFontSettings(bufparams,pos).language()->lang() == "hebrew") + bv->insertInset(new InsetQuotes(c, bufparams)); + else bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\"")); break; }