Some cleanup (31 lines gone, three global variables) Andre'
-- Those who desire to give up Freedom in order to gain Security, will not have, nor do they deserve, either one. (T. Jefferson or B. Franklin or both...)
Index: paragraph.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph.C,v retrieving revision 1.297 diff -u -p -r1.297 paragraph.C --- paragraph.C 31 Jul 2003 12:25:35 -0000 1.297 +++ paragraph.C 31 Jul 2003 12:50:47 -0000 @@ -58,17 +58,6 @@ using std::upper_bound; using lyx::pos_type; -// this is a minibuffer - -namespace { - -char minibuffer_char; -LyXFont minibuffer_font; -InsetOld * minibuffer_inset; - -} // namespace anon - - Paragraph::Paragraph() : pimpl_(new Paragraph::Pimpl(this)) { @@ -249,44 +238,6 @@ void Paragraph::validate(LaTeXFeatures & { pimpl_->validate(features, *layout()); } - - -void Paragraph::cutIntoMinibuffer(BufferParams const & bparams, pos_type pos) -{ - minibuffer_char = getChar(pos); - minibuffer_font = getFontSettings(bparams, pos); - minibuffer_inset = 0; - if (minibuffer_char == Paragraph::META_INSET) { - if (getInset(pos)) { - // the inset is not in a paragraph anymore - minibuffer_inset = insetlist.release(pos); - minibuffer_inset->parOwner(0); - } else { - minibuffer_inset = 0; - minibuffer_char = ' '; - // This reflects what GetInset() does (ARRae) - } - } -} - - -bool Paragraph::insertFromMinibuffer(pos_type pos) -{ - if (minibuffer_char == Paragraph::META_INSET) { - if (!insetAllowed(minibuffer_inset->lyxCode())) - return false; - insertInset(pos, minibuffer_inset, minibuffer_font); - } else { - LyXFont f = minibuffer_font; - if (!checkInsertChar(f)) - return false; - insertChar(pos, minibuffer_char, f); - } - return true; -} - - -// end of minibuffer void Paragraph::eraseIntern(lyx::pos_type pos) Index: paragraph.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph.h,v retrieving revision 1.91 diff -u -p -r1.91 paragraph.h --- paragraph.h 31 Jul 2003 12:25:35 -0000 1.91 +++ paragraph.h 31 Jul 2003 12:50:47 -0000 @@ -258,12 +258,6 @@ public: InsetOld * getInset(lyx::pos_type pos); /// InsetOld const * getInset(lyx::pos_type pos) const; - /** important for cut and paste - Temporary change from BufferParams to Buffer. Will revert when we - get rid of the argument to InsetOld::clone(Buffer const &) */ - void cutIntoMinibuffer(BufferParams const &, lyx::pos_type pos); - /// - bool insertFromMinibuffer(lyx::pos_type pos); /// bool isHfill(lyx::pos_type pos) const; Index: paragraph_funcs.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph_funcs.C,v retrieving revision 1.56 diff -u -p -r1.56 paragraph_funcs.C --- paragraph_funcs.C 30 Jul 2003 23:29:49 -0000 1.56 +++ paragraph_funcs.C 31 Jul 2003 12:50:47 -0000 @@ -46,6 +46,36 @@ using std::endl; using std::ostream; +namespace { + +bool moveItem(Paragraph & from, Paragraph & to, + BufferParams const & params, pos_type i, pos_type j) +{ + char const tmpchar = from.getChar(i); + LyXFont tmpfont = from.getFontSettings(params, i); + + if (tmpchar == Paragraph::META_INSET) { + InsetOld * tmpinset = 0; + if (from.getInset(i)) { + // the inset is not in a paragraph anymore + tmpinset = from.insetlist.release(i); + tmpinset->parOwner(0); + } + + if (!to.insetAllowed(tmpinset->lyxCode())) + return false; + to.insertInset(j, tmpinset, tmpfont); + } else { + if (!to.checkInsertChar(tmpfont)) + return false; + to.insertChar(j, tmpchar, tmpfont); + } + return true; +} + +} + + void breakParagraph(BufferParams const & bparams, ParagraphList & paragraphs, ParagraphList::iterator par, @@ -106,16 +136,15 @@ void breakParagraph(BufferParams const & pos_type j = pos; for (; i <= pos_end; ++i) { - Change::Type change(par->lookupChange(i)); - par->cutIntoMinibuffer(bparams, i); - if (tmp->insertFromMinibuffer(j - pos)) { + Change::Type change = par->lookupChange(i); + if (moveItem(*par, *tmp, bparams, i, j - pos)) { tmp->setChange(j - pos, change); ++j; } } - for (i = pos_end; i >= pos; --i) { + + for (i = pos_end; i >= pos; --i) par->eraseIntern(i); - } } if (pos) @@ -163,15 +192,12 @@ void breakParagraphConservative(BufferPa // paragraph pos_type pos_end = par->size() - 1; - for (pos_type i = pos, j = pos; i <= pos_end; ++i) { - par->cutIntoMinibuffer(bparams, i); - if (tmp->insertFromMinibuffer(j - pos)) + for (pos_type i = pos, j = pos; i <= pos_end; ++i) + if (moveItem(*par, *tmp, bparams, i, j - pos)) ++j; - } - for (pos_type k = pos_end; k >= pos; --k) { + for (pos_type k = pos_end; k >= pos; --k) par->erase(k); - } } } @@ -191,11 +217,9 @@ void mergeParagraph(BufferParams const & pos_type pos_insert = par->size(); // ok, now copy the paragraph - for (pos_type i = 0, j = 0; i <= pos_end; ++i) { - the_next->cutIntoMinibuffer(bparams, i); - if (par->insertFromMinibuffer(pos_insert + j)) + for (pos_type i = 0, j = 0; i <= pos_end; ++i) + if (moveItem(*the_next, *par, bparams, i, pos_insert + j)) ++j; - } paragraphs.erase(the_next); }