]> git.lyx.org Git - features.git/commitdiff
Fixed cut&paste bugs and added freespacing for ERT Insets.
authorJürgen Vigna <jug@sad.it>
Thu, 29 Nov 2001 16:29:30 +0000 (16:29 +0000)
committerJürgen Vigna <jug@sad.it>
Thu, 29 Nov 2001 16:29:30 +0000 (16:29 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3115 a592a061-630c-0410-9148-cb99ea01b6c8

12 files changed:
src/ChangeLog
src/CutAndPaste.C
src/buffer.C
src/insets/ChangeLog
src/insets/insetcollapsable.C
src/insets/insetcollapsable.h
src/insets/insettext.C
src/paragraph.C
src/paragraph.h
src/paragraph_pimpl.C
src/text.C
src/text2.C

index f1750532da5d07833fa0d4cb633706836e6f7803..1c8fc58a782f1c7929bfb5d7671614550200c52d 100644 (file)
@@ -1,5 +1,15 @@
 2001-11-29  Juergen Vigna  <jug@sad.it>
 
+       * text.C: added support for paragraph::isFreeSpacing()
+
+       * buffer.C: same as above
+
+       * paragraph.h: inserted isFreeSpacing() function to enable
+       FreeSpacing inside InsetERT.
+
+       * CutAndPaste.C (cutSelection/copySelection): set the inset_owner
+       of the paragraph's in the cut/copy buffer to 0!
+
        * text2.C (removeRow): remove the assert as it can!
 
        * lyxtext.h: added helper function firstRow returning firstrow and
index 058ee2d6a4ba562d142a7fce29e1b3b6a7bab096..80c62c28f2b6892cb04e4339af04a63bec782279 100644 (file)
@@ -137,6 +137,12 @@ bool CutAndPaste::cutSelection(Paragraph * startpar, Paragraph ** endpar,
                        startpar->pasteParagraph(current_view->buffer()->params);
                        (*endpar) = startpar; // this because endpar gets deleted here!
                }
+               // this paragraph's are of noone's owner!
+               Paragraph * p = buf;
+               while(p) {
+                       p->setInsetOwner(0);
+                       p = p->next();
+               }
        }
        return true;
 }
@@ -188,6 +194,12 @@ bool CutAndPaste::copySelection(Paragraph * startpar, Paragraph * endpar,
                while (tmppar2->size() > tmpi2) {
                        tmppar2->erase(tmppar2->size() - 1);
                }
+               // this paragraph's are of noone's owner!
+               tmppar = buf;
+               while(tmppar) {
+                       tmppar->setInsetOwner(0);
+                       tmppar = tmppar->next();
+               }
        }
        return true;
 }
index d58ef540abba0bab9621b472228b1c90bf14e4af..a253c872291b18ea5f3c3823c05852b3301dbdfb 100644 (file)
@@ -1065,7 +1065,7 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
                                            par->getLayout());
 
                // Insets don't make sense in a free-spacing context! ---Kayvan
-               if (layout.free_spacing) {
+               if (layout.free_spacing || par->isFreeSpacing()) {
                        if (lex.isOK()) {
                                lex.next();
                                string next_token = lex.getString();
@@ -1123,7 +1123,7 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
                        textclasslist.Style(params.textclass, 
                                            par->getLayout());
 
-               if (layout.free_spacing) {
+               if (layout.free_spacing || par->isFreeSpacing()) {
                        par->insertChar(pos, ' ', font);
                } else {
                        Inset * inset = new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
@@ -1364,11 +1364,12 @@ void Buffer::insertStringAsLines(Paragraph *& par, pos_type & pos,
                        }
                        // do not insert consecutive spaces if !free_spacing
                } else if ((*cit == ' ' || *cit == '\t') &&
-                          space_inserted && !layout.free_spacing)
+                          space_inserted && !layout.free_spacing &&
+                                  !par->isFreeSpacing())
                {
                        continue;
                } else if (*cit == '\t') {
-                       if (!layout.free_spacing) {
+                       if (!layout.free_spacing && !par->isFreeSpacing()) {
                                // tabs are like spaces here
                                par->insertChar(pos, ' ', font);
                                ++pos;
@@ -2927,7 +2928,8 @@ void Buffer::simpleLinuxDocOnePar(ostream & os,
                } else {
                        string sgml_string;
                        if (par->sgmlConvertChar(c, sgml_string)
-                           && !style.free_spacing) { 
+                           && !style.free_spacing && !par->isFreeSpacing())
+                       { 
                                // in freespacing mode, spaces are
                                // non-breaking characters
                                if (desc_on) {// if char is ' ' then...
@@ -3314,7 +3316,7 @@ void Buffer::simpleDocBookOnePar(ostream & os,
 
                        if (style.pass_thru) {
                                os << c;
-                       } else if(style.free_spacing || c != ' ') {
+                       } else if(style.free_spacing || par->isFreeSpacing() || c != ' ') {
                                        os << sgml_string;
                        } else if (desc_on ==1) {
                                ++char_line_count;
index 310c2b173960938f9bf1d18e1f69b1da0a7d376f..f83fa34f210c49a1a7ec92748cd3b561d67cfe94 100644 (file)
@@ -3,6 +3,7 @@
        * insettext.C: inserted a reinitLyXText function everywhere I delete
        the paragraphs! This should fixe the crashes we had.
        Also use the new function firstRow() instead of getRowNearY(dummy_y)
+       (paragraph): set the InsetOwner() of the new paragraphs!
 
 2001-11-28  André Pönitz <poenitz@gmx.net>
 
index 1acb5541d09970f915776e6f4e24a7cb7c8163f7..01e0d11abf8143d840fe59de3fdb12b4431d42be 100644 (file)
@@ -376,7 +376,7 @@ int InsetCollapsable::latex(Buffer const * buf, ostream & os,
        return inset.latex(buf, os, fragile, free_spc);
 }
 
-
+#if 0
 int InsetCollapsable::getMaxWidth(BufferView * bv,
                                   UpdatableInset const * in) const
 {
@@ -394,6 +394,7 @@ int InsetCollapsable::getMaxWidth(BufferView * bv,
        return UpdatableInset::getMaxWidth(bv, in);
 #endif
 }
+#endif
 
 
 void InsetCollapsable::update(BufferView * bv, LyXFont const & font,
index 06cb34f34235bcdfc2a4fdf8c3959b9084d2a6fa..0e15112f60cdc515358b707935efbfe60cd1475a 100644 (file)
@@ -136,8 +136,10 @@ public:
        ///
        void setAutoCollapse(bool f) { autocollapse = f; }
 #endif
+#if 0
        ///
        int getMaxWidth(BufferView *, UpdatableInset const *) const;
+#endif
        ///
        LyXText * getLyXText(BufferView const *, bool const recursive) const;
        ///
index c85c6be95f6b7667c69f05453e023ce78bb2e8dd..73c43939e226c1afa8d08114ca1d70ecdd441cdc 100644 (file)
@@ -2335,6 +2335,12 @@ Paragraph * InsetText::paragraph() const
 void InsetText::paragraph(Paragraph * p)
 {
        par = p;
+       // set ourself as owner for all the paragraphs inserted!
+       Paragraph * np = par;
+       while (np) {
+               np->setInsetOwner(this);
+               np = np->next();
+       }
        reinitLyXText();
        // redraw myself when asked for
        need_update = INIT;
index df3964ccc48e25271d2c59eac235c7a1b5c9bc74..76311c25589cc39b6d4d60a381c2fbcea9f640f6 100644 (file)
@@ -928,8 +928,11 @@ void Paragraph::makeSameLayout(Paragraph const * par)
 
 int Paragraph::stripLeadingSpaces(LyXTextClassList::size_type tclass) 
 {
-       if (textclasslist.Style(tclass, getLayout()).free_spacing)
+       if (textclasslist.Style(tclass, getLayout()).free_spacing ||
+               isFreeSpacing())
+       {
                return 0;
+       }
        
        int i = 0;
        while (size()
@@ -2156,3 +2159,13 @@ Paragraph * Paragraph::getParFromID(int id) const
 {
        return pimpl_->getParFromID(id);
 }
+
+
+bool Paragraph::isFreeSpacing() const
+{
+       // for now we just need this, later should we need this in some
+       // other way we can always add a function to Inset::() too.
+       if (pimpl_->inset_owner && pimpl_->inset_owner->owner())
+               return (pimpl_->inset_owner->owner()->lyxCode() == Inset::ERT_CODE);
+       return false;
+}
index d97b8c62a42ab75be979b704d4e402384a6adcbc..3662fee3e5a760e998e22ff6aa9e90c1af35f0ea 100644 (file)
@@ -334,6 +334,8 @@ public:
 #endif
        ///
        bool sgmlConvertChar(char c, string & sgml_string);
+       ///
+       bool isFreeSpacing() const;
 
        ParagraphParameters & params();
        ParagraphParameters const & params() const;
index c28db75b3316c85d8a8a3028c44f0e169b7d6b38..82e73c9dddacda0051c7544eb995c9339d21f485 100644 (file)
@@ -219,9 +219,9 @@ void Paragraph::Pimpl::erase(pos_type pos)
 
 
 void Paragraph::Pimpl::simpleTeXBlanks(std::ostream & os, TexRow & texrow,
-                                      pos_type const i,
-                                      int & column, LyXFont const & font,
-                                      LyXLayout const & style)
+                                       pos_type const i,
+                                       int & column, LyXFont const & font,
+                                       LyXLayout const & style)
 {
        if (style.pass_thru) return;
        if (column > tex_code_break_column
@@ -230,6 +230,7 @@ void Paragraph::Pimpl::simpleTeXBlanks(std::ostream & os, TexRow & texrow,
            && (i < size() - 1)
            // same in FreeSpacing mode
            && !style.free_spacing
+               && !owner_->isFreeSpacing()
            // In typewriter mode, we want to avoid 
            // ! . ? : at the end of a line
            && !(font.family() == LyXFont::TYPEWRITER_FAMILY
@@ -307,7 +308,7 @@ void Paragraph::Pimpl::simpleTeXSpecialChars(Buffer const * buf,
                        }
 
                        int tmp = inset->latex(buf, os, moving_arg,
-                                              style.free_spacing);
+                                              style.free_spacing);
 
                        if (close)
                                os << "}";
index 3732c0c4160b3e8e1a2a515aa0ba708d6a6dfbb3..8e5d3ea8d41b499d9aa5ee4cda39c7b44b7810fd 100644 (file)
@@ -1746,7 +1746,8 @@ void LyXText::insertChar(BufferView * bview, char c)
 
        bool const freeSpacing = 
                textclasslist.Style(bview->buffer()->params.textclass,
-                              cursor.row()->par()->getLayout()).free_spacing;
+                              cursor.row()->par()->getLayout()).free_spacing ||
+               cursor.row()->par()->isFreeSpacing();
 
 
        if (lyxrc.auto_number) {
index 3350c4367b97c1423733f840c6e97a7bc37dbac7..0c092dff9a053ace05a83a13e0f4d6d0990dc799 100644 (file)
@@ -2376,8 +2376,11 @@ void LyXText::deleteEmptyParagraphMechanism(BufferView * bview,
 
        // We allow all kinds of "mumbo-jumbo" when freespacing.
        if (textclasslist.Style(bview->buffer()->params.textclass,
-                               old_cursor.par()->getLayout()).free_spacing)
+                                                       old_cursor.par()->getLayout()).free_spacing ||
+               old_cursor.par()->isFreeSpacing())
+       {
                return;
+       }
 
        bool deleted = false;