]> git.lyx.org Git - features.git/commitdiff
add a ParagraphList::insert, adjust other funcs accordingly
authorLars Gullik Bjønnes <larsbj@gullik.org>
Tue, 4 Mar 2003 21:40:36 +0000 (21:40 +0000)
committerLars Gullik Bjønnes <larsbj@gullik.org>
Tue, 4 Mar 2003 21:40:36 +0000 (21:40 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6345 a592a061-630c-0410-9148-cb99ea01b6c8

src/ChangeLog
src/CutAndPaste.C
src/ParagraphList.C
src/ParagraphList.h
src/buffer.C
src/buffer.h
src/paragraph.C
src/paragraph_funcs.C
src/paragraph_funcs.h
src/text.C

index c749add78ac86f1ee1c45244bec4dc5a8b708a46..916f39d39d3e2724cf58ea55bf650aa777b62ca2 100644 (file)
@@ -1,5 +1,21 @@
 2003-03-04  Lars Gullik Bjønnes  <larsbj@gullik.net>
 
+       * text.C (breakParagraph): adjust
+
+       * paragraph_funcs.C (breakParagraph): take a Buffer* instead of a
+       BufferParams& as arg.
+       (breakParagraph): use ParagraphList::insert
+       (breakParagraphConservative): take a Buffer* instead of a
+       BufferParams& as arg.
+       (breakParagraphConservative): use ParagraphList::insert.
+
+       * buffer.C (insertStringAsLines): un-const it
+       (insertStringAsLines): adjust
+
+       * ParagraphList.C (insert): new function
+
+       * CutAndPaste.C (pasteSelection): adjust
+
        * text.C (backspace): adjust
 
        * tabular.C (SetMultiColumn): adjust
index f019f906d09c1e9d2f04c342129e06efd87d4e67..94370cd80b08c0984f4b65c8d7099d63e9ff78a9 100644 (file)
@@ -361,7 +361,7 @@ bool CutAndPaste::pasteSelection(Paragraph ** par, Paragraph ** endpar,
                // if necessary
                if (((*par)->size() > pos) || !(*par)->next()) {
                        breakParagraphConservative(
-                               current_view->buffer()->params, *par, pos);
+                               current_view->buffer(), *par, pos);
                        paste_the_end = true;
                }
                // set the end for redoing later
index 136071aa7a471375c669ba203ab72ddfbf863357..c462fd3d395b5bdc1b18aeec64c5469d1ba7858f 100644 (file)
@@ -85,6 +85,18 @@ ParagraphList::ParagraphList()
 {}
 
 
+ParagraphList::iterator
+ParagraphList::insert(ParagraphList::iterator it, Paragraph * par)
+{
+       Paragraph * prev = it->previous();
+       par->next(&*it);
+       par->previous(prev);
+       prev->next(par);
+       it->previous(par);
+       return iterator(par);
+}
+
+
 void ParagraphList::clear()
 {
        while (parlist) {
index b81ac00690dda63d87e89a6b81103efd73aff5a3..7223b58e08c7c1baeb87d3af6959b813cc980dbd 100644 (file)
@@ -46,6 +46,8 @@ public:
        ///
        ParagraphList();
        ///
+       iterator insert(iterator it, Paragraph * par);
+       ///
        void clear();
        ///
        void erase(iterator it);
index 030e4f3d556c1f0c619b0b500f3912b28d602156..d091ac51e867a2cec56a97b67b30cc5bf48342df 100644 (file)
@@ -1015,7 +1015,7 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
 
 // needed to insert the selection
 void Buffer::insertStringAsLines(Paragraph *& par, pos_type & pos,
-                                LyXFont const & fn,string const & str) const
+                                LyXFont const & fn,string const & str)
 {
        LyXLayout_ptr const & layout = par->layout();
 
@@ -1030,7 +1030,7 @@ void Buffer::insertStringAsLines(Paragraph *& par, pos_type & pos,
            cit != str.end(); ++cit) {
                if (*cit == '\n') {
                        if (autobreakrows && (!par->empty() || layout->keepempty)) {
-                               breakParagraph(params, par, pos,
+                               breakParagraph(this, par, pos,
                                               layout->isEnvironment());
                                par = par->next();
                                pos = 0;
index e03e9015fb1622ce2b443baf586657507403bcf5..e43a5939ad12062df3fe47f6ae79b4965af7b0c0 100644 (file)
@@ -112,7 +112,7 @@ public:
                                        LyXFont &);
        ///
        void insertStringAsLines(Paragraph *&, lyx::pos_type &,
-                                LyXFont const &, string const &) const;
+                                LyXFont const &, string const &);
        ///
        Paragraph * getParFromID(int id) const;
 private:
index 517c9f00692b1264ab4ba05b9960cd8f70da9c94..ad90baabfdc910980836242b02aaa21993c9960a 100644 (file)
@@ -80,6 +80,7 @@ Paragraph::Paragraph()
 
 #ifndef NO_NEXT
 // This constructor inserts the new paragraph in a list.
+// It is placed after par.
 Paragraph::Paragraph(Paragraph * par)
        : pimpl_(new Paragraph::Pimpl(this))
 {
index 77462f1e936dcc2c5e0fe2e4f7f151297edd5893..5796f158c1bfac6ac855efc9ceaec1b4fa758f09 100644 (file)
@@ -29,13 +29,17 @@ using lyx::pos_type;
 using std::endl;
 using std::ostream;
 
-void breakParagraph(BufferParams const & bparams,
+void breakParagraph(Buffer * buf,
                    ParagraphList::iterator par,
                    pos_type pos,
                    int flag)
 {
+       BufferParams const & bparams = buf->params;
+
        // create a new paragraph, and insert into the list
-       Paragraph * tmp = new Paragraph(&*par);
+       ParagraphList::iterator tmp = buf->paragraphs.insert(boost::next(par),
+                                                            new Paragraph);
+
        // without doing that we get a crash when typing <Return> at the
        // end of a paragraph
        tmp->layout(bparams.getLyXTextClass().defaultLayout());
@@ -126,12 +130,15 @@ void breakParagraph(BufferParams const & bparams,
 }
 
 
-void breakParagraphConservative(BufferParams const & bparams,
+void breakParagraphConservative(Buffer * buf,
                                ParagraphList::iterator par,
                                pos_type pos)
 {
+       BufferParams const & bparams = buf->params;
+
        // create a new paragraph
-       Paragraph * tmp = new Paragraph(&*par);
+       ParagraphList::iterator tmp = buf->paragraphs.insert(boost::next(par),
+                                                            new Paragraph);
        tmp->makeSameLayout(&*par);
 
        // When can pos > Last()?
index fa7d69419fb253c5f472a934822571406732819c..ace89ee07d963e597e2d7f67b7adb8b2ef182b80 100644 (file)
@@ -21,13 +21,13 @@ class Paragraph;
 class TexRow;
 
 ///
-void breakParagraph(BufferParams const & bparams,
+void breakParagraph(Buffer * buf,
                    ParagraphList::iterator par,
                    lyx::pos_type pos,
                    int flag);
 
 ///
-void breakParagraphConservative(BufferParams const & bparams,
+void breakParagraphConservative(Buffer * buf,
                                ParagraphList::iterator par,
                                lyx::pos_type pos);
 
index 2925ee7f68cb92be1e46fb6d068ce983243e7bc3..baf693d5f4f8198478b083877075e785094ff8aa 100644 (file)
@@ -1363,7 +1363,7 @@ void LyXText::breakParagraph(BufferView * bview, char keep_layout)
        // paragraph before or behind and we should react on that one
        // but we can fix this in 1.3.0 (Jug 20020509)
        bool const isempty = (layout->keepempty && cursor.par()->empty());
-       ::breakParagraph(bview->buffer()->params, cursor.par(), cursor.pos(),
+       ::breakParagraph(bview->buffer(), cursor.par(), cursor.pos(),
                       keep_layout);
 
        // well this is the caption hack since one caption is really enough