From 58fd3c844a88ea74901e5d8b22e94939a67f70d5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Thu, 31 Jul 2003 13:12:21 +0000 Subject: [PATCH] put two functions in one, remove global variables git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7464 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 7 +++++- src/paragraph.C | 49 --------------------------------------- src/paragraph.h | 6 ----- src/paragraph_funcs.C | 54 +++++++++++++++++++++++++++++++------------ 4 files changed, 45 insertions(+), 71 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 63d6fb22da..b6f2964323 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,7 +1,12 @@ 2003-07-30 André Pönitz - * Paragraph.[Ch] (copyIntoMinibuffer) removed unused function + * paragraph.[Ch] (copyIntoMinibuffer): removed unused function + + * paragraph.[Ch] (cutIntoMinibuffer, insertFromMinibuffer): + create a single function... + + * paragraph_funcs.C (moveItem): ... here. 2003-07-30 Martin Vermeer diff --git a/src/paragraph.C b/src/paragraph.C index 1d9f555e86..c5c3bad5a9 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -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)) { @@ -251,44 +240,6 @@ void Paragraph::validate(LaTeXFeatures & features) const } -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) { pimpl_->eraseIntern(pos); diff --git a/src/paragraph.h b/src/paragraph.h index 1fa4612bfb..27aad6fc23 100644 --- a/src/paragraph.h +++ b/src/paragraph.h @@ -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; diff --git a/src/paragraph_funcs.C b/src/paragraph_funcs.C index 61e392a767..e46407a197 100644 --- a/src/paragraph_funcs.C +++ b/src/paragraph_funcs.C @@ -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 & bparams, 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(BufferParams const & bparams, // 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 & bparams, 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); } -- 2.39.2