]> git.lyx.org Git - features.git/commitdiff
change tracking:
authorMichael Schmitt <michael.schmitt@teststep.org>
Tue, 24 Oct 2006 21:38:47 +0000 (21:38 +0000)
committerMichael Schmitt <michael.schmitt@teststep.org>
Tue, 24 Oct 2006 21:38:47 +0000 (21:38 +0000)
* src/*.C:
* src/insets/*.C: implement rejectChanges() in analogy to
acceptChanges();

* src/paragraph_pimpl.C: add assertions for pos, start, and
end parameters

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15542 a592a061-630c-0410-9148-cb99ea01b6c8

src/insets/insetbase.h
src/insets/insettabular.C
src/insets/insettabular.h
src/insets/insettext.C
src/insets/insettext.h
src/paragraph.C
src/paragraph.h
src/paragraph_pimpl.C
src/paragraph_pimpl.h
src/text.C

index eef82e0259df1bfa646f3fe8e1ca144ab56c9de9..55524e17c7c94af064212972cba6512bbd7f3bfc 100644 (file)
@@ -402,6 +402,8 @@ public:
        virtual void setChange(Change const &) {}
        /// accept the changes within the inset
        virtual void acceptChanges() {};
+       /// reject the changes within the inset
+       virtual void rejectChanges() {};
 
        /// pretty arbitrary
        virtual int width() const { return 10; }
index c6f82d3a4c3ca1234bec2c3b34f212377bfdc006..18ad8575301eee95e0b103b3a7058ff4804d45c6 100644 (file)
@@ -1921,6 +1921,13 @@ void InsetTabular::acceptChanges()
 }
 
 
+void InsetTabular::rejectChanges()
+{
+       for (idx_type idx = 0; idx < nargs(); ++idx)
+               cell(idx)->rejectChanges();
+}
+
+
 bool InsetTabular::forceDefaultParagraphs(idx_type cell) const
 {
        return tabular.getPWidth(cell).zero();
index 469e3d27e4d9c577279bfedaa8ed290910d39dd1..a43e22e0bd9fd1e2753982a7f5e4ee655bd551c2 100644 (file)
@@ -119,6 +119,8 @@ public:
        void setChange(Change const & change);
        /// accept the changes within the inset
        void acceptChanges();
+       /// reject the changes within the inset
+       void rejectChanges();
 
        // this should return true if we have a "normal" cell, otherwise false.
        // "normal" means without width set!
index 39fe2606a0dec3944c94069f30013c23009e9b87..96c7dcdf8e546dfb5f0874ef5513c8273c0db20a 100644 (file)
@@ -284,6 +284,18 @@ void InsetText::acceptChanges()
 }
 
 
+void InsetText::rejectChanges()
+{
+       ParagraphList::iterator pit = paragraphs().begin();
+       ParagraphList::iterator end = paragraphs().end();
+       for (; pit != end; ++pit) {
+               // FIXME: change tracking (MG)
+               // we must handle end-of-par chars!
+               pit->rejectChanges(0, pit->size() + 1);
+       }
+}
+
+
 int InsetText::latex(Buffer const & buf, odocstream & os,
                     OutputParams const & runparams) const
 {
index 34219d0bf65bdb2d8fbc290cf8485bb7f2216807..0b33eb23eb78a528fc5a8e3873ec399b5ed4282e 100644 (file)
@@ -106,6 +106,8 @@ public:
        void setChange(Change const & change);
        /// accept the changes within the inset
        void acceptChanges();
+       /// reject the changes within the inset
+       void rejectChanges();
 
        /// append text onto the existing text
        void appendParagraphs(Buffer * bp, ParagraphList &);
index 6f9701139c36bad41940c77842a640bcb16ffdd0..4c9cf2982896c49cde3854a56d327654fdff0276 100644 (file)
@@ -1447,9 +1447,9 @@ void Paragraph::acceptChanges(pos_type start, pos_type end)
 }
 
 
-void Paragraph::rejectChange(pos_type start, pos_type end)
+void Paragraph::rejectChanges(pos_type start, pos_type end)
 {
-       return pimpl_->rejectChange(start, end);
+       return pimpl_->rejectChanges(start, end);
 }
 
 
index 60dd0fba9366799e9bd4b439982fa5a884b0442e..77635bf2a318f4d0b14ca49704e935da8b8cccc4 100644 (file)
@@ -220,8 +220,8 @@ public:
        /// accept changes within the given range
        void acceptChanges(pos_type start, pos_type end);
 
-       /// reject change
-       void rejectChange(pos_type start, pos_type end);
+       /// reject changes within the given range
+       void rejectChanges(pos_type start, pos_type end);
 
        /// Paragraphs can contain "manual labels", for example, Description
        /// environment. The text for this user-editable label is stored in
index 1d9512a328e87d4da8f2cfd9ff783066401d6dfd..df802cec42a46f2d5433a51107a2553dc0d280f1 100644 (file)
@@ -89,6 +89,9 @@ void Paragraph::Pimpl::setContentsFromPar(Paragraph const & par)
 
 bool Paragraph::Pimpl::isChanged(pos_type start, pos_type end) const
 {
+       BOOST_ASSERT(start >= 0 && start <= size());
+       BOOST_ASSERT(end > start && end <= size() + 1);
+
        return changes_.isChanged(start, end);
 }
 
@@ -111,6 +114,8 @@ void Paragraph::Pimpl::setChange(Change const & change)
 
 void Paragraph::Pimpl::setChange(pos_type pos, Change const & change)
 {
+       BOOST_ASSERT(pos >= 0 && pos <= size());
+
        changes_.set(change, pos);
 
        // FIXME: change tracking (MG)
@@ -123,12 +128,17 @@ void Paragraph::Pimpl::setChange(pos_type pos, Change const & change)
 
 Change const Paragraph::Pimpl::lookupChange(pos_type pos) const
 {
+       BOOST_ASSERT(pos >= 0 && pos <= size());
+
        return changes_.lookup(pos);
 }
 
 
 void Paragraph::Pimpl::acceptChanges(pos_type start, pos_type end)
 {
+       BOOST_ASSERT(start >= 0 && start <= size());
+       BOOST_ASSERT(end > start && end <= size() + 1);
+       
        for (pos_type pos = start; pos < end; ++pos) {
                switch (lookupChange(pos).type) {
                        case Change::UNCHANGED:
@@ -139,8 +149,8 @@ void Paragraph::Pimpl::acceptChanges(pos_type start, pos_type end)
                                break;
 
                        case Change::DELETED:
-                               // Suppress access to nonexistent
-                               // "end-of-paragraph char":
+                               // Suppress access to non-existent
+                               // "end-of-paragraph char"
                                if (pos < size()) {
                                        eraseChar(pos, false);
                                        --end;
@@ -157,52 +167,50 @@ void Paragraph::Pimpl::acceptChanges(pos_type start, pos_type end)
 }
 
 
-void Paragraph::Pimpl::rejectChange(pos_type start, pos_type end)
+void Paragraph::Pimpl::rejectChanges(pos_type start, pos_type end)
 {
-       // FIXME: change tracking (MG)
-       return;
-
-       // care for empty pars
+       BOOST_ASSERT(start >= 0 && start <= size());
+       BOOST_ASSERT(end > start && end <= size() + 1);
 
-       pos_type i = start;
-
-       for (; i < end; ++i) {
-               switch (lookupChange(i).type) {
+       for (pos_type pos = start; pos < end; ++pos) {
+               switch (lookupChange(pos).type) {
                        case Change::UNCHANGED:
                                break;
 
                        case Change::INSERTED:
-                               if (i < size()) {
-                                       eraseChar(i, false);
+                               // Suppress access to non-existent
+                               // "end-of-paragraph char"
+                               if (pos < size()) {
+                                       eraseChar(pos, false);
                                        --end;
-                                       --i;
+                                       --pos;
                                }
                                break;
 
                        case Change::DELETED:
-                               // FIXME: change tracking (MG)
-                               changes_.set(Change(Change::UNCHANGED), i);
-                               // No real char at position size():
-                               if (i < size() && owner_->isInset(i))
-                                       // FIXME: change tracking (MG)
-                                       owner_->getInset(i)->setChange(Change(Change::UNCHANGED));
+                               changes_.set(Change(Change::UNCHANGED), pos);
                                break;
                }
+
+               // also reject changes in nested insets
+               if (pos < size() && owner_->isInset(pos)) {
+                       owner_->getInset(pos)->rejectChanges();
+               }
        }
-       // FIXME: change tracking (MG)
-       // changes_.reset(Change::UNCHANGED);
 }
 
 
 Paragraph::value_type Paragraph::Pimpl::getChar(pos_type pos) const
 {
+       BOOST_ASSERT(pos >= 0 && pos <= size());
+
        return owner_->getChar(pos);
 }
 
 
 void Paragraph::Pimpl::insertChar(pos_type pos, value_type c, Change const & change)
 {
-       BOOST_ASSERT(pos <= size());
+       BOOST_ASSERT(pos >= 0 && pos <= size());
 
        // track change
        changes_.insert(change, pos);
@@ -235,7 +243,7 @@ void Paragraph::Pimpl::insertInset(pos_type pos, InsetBase * inset,
                                    Change const & change)
 {
        BOOST_ASSERT(inset);
-       BOOST_ASSERT(pos <= size());
+       BOOST_ASSERT(pos >= 0 && pos <= size());
 
        insertChar(pos, META_INSET, change);
        BOOST_ASSERT(owner_->text_[pos] == META_INSET);
@@ -247,7 +255,7 @@ void Paragraph::Pimpl::insertInset(pos_type pos, InsetBase * inset,
 
 bool Paragraph::Pimpl::eraseChar(pos_type pos, bool trackChanges)
 {
-       BOOST_ASSERT(pos <= size());
+       BOOST_ASSERT(pos >= 0 && pos <= size());
 
        if (trackChanges) {
                Change::Type changetype(changes_.lookup(pos).type);
@@ -317,6 +325,9 @@ bool Paragraph::Pimpl::eraseChar(pos_type pos, bool trackChanges)
 
 int Paragraph::Pimpl::eraseChars(pos_type start, pos_type end, bool trackChanges)
 {
+       BOOST_ASSERT(start >= 0 && start <= size());
+       BOOST_ASSERT(end > start && end <= size() + 1);
+
        pos_type i = start;
        for (pos_type count = end - start; count; --count) {
                if (!eraseChar(i, trackChanges))
index facbcb22fcb69c48c74c7325c1ce465af68f305e..221fb941432c0082ec69ddf858f657c902c2c58f 100644 (file)
@@ -51,8 +51,8 @@ public:
        void setChange(pos_type pos, Change const & change);
        /// accept changes within the given range
        void acceptChanges(pos_type start, pos_type end);
-       /// reject change
-       void rejectChange(pos_type start, pos_type end);
+       /// reject changes within the given range
+       void rejectChanges(pos_type start, pos_type end);
 
        ///
        value_type getChar(pos_type pos) const;
index d953f955d376a33bca846f1153e0060a34d7cbf1..8ab02dfa3519268a00ff49c1559357addd973ae6 100644 (file)
@@ -1501,7 +1501,7 @@ void LyXText::rejectChange(LCursor & cur)
                pos_type left  = ( pit == it.pit() ? it.pos() : 0 );
                pos_type right =
                    ( pit == et.pit() ? et.pos() : pars_[pit].size() + 1 );
-               pars_[pit].rejectChange(left, right);
+               pars_[pit].rejectChanges(left, right);
        }
        if (isInserted) {
                ParagraphList & plist = paragraphs();