]> git.lyx.org Git - features.git/commitdiff
put two functions in one, remove global variables
authorAndré Pönitz <poenitz@gmx.net>
Thu, 31 Jul 2003 13:12:21 +0000 (13:12 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Thu, 31 Jul 2003 13:12:21 +0000 (13:12 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7464 a592a061-630c-0410-9148-cb99ea01b6c8

src/ChangeLog
src/paragraph.C
src/paragraph.h
src/paragraph_funcs.C

index 63d6fb22da8ac4591e029d3093b576c020a93480..b6f2964323579b271d2330742aaf09607845b050 100644 (file)
@@ -1,7 +1,12 @@
 
 2003-07-30  André Pönitz  <poenitz@gmx.net>
 
-       * 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  <martin.vermeer@hut.fi>
 
index 1d9f555e8631bfc6e4343beed7cfaac9cae4643f..c5c3bad5a9dc4ecb122bda4e6714bd4cae899c89 100644 (file)
@@ -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);
index 1fa4612bfb000e08ad185e6021fd69314008a548..27aad6fc233de5a5d5271108c3767c9d90e1f0c1 100644 (file)
@@ -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 61e392a767ae529c038c4db1a56b00d86533374c..e46407a1971965744a1ee3df0ebe9c023628da8e 100644 (file)
@@ -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);
 }