From cbe1309573c8969ac85855f644cf18e267cad20a Mon Sep 17 00:00:00 2001 From: Michael Schmitt Date: Thu, 19 Oct 2006 07:12:48 +0000 Subject: [PATCH] Change tracking: src/paragraph.h: src/paragraph.C: src/paragraph_pimpl.h: src/paragraph_pimpl.C: setChange(...) replaces markErased(...); pass Change parameters as const reference src/insets/insettext.C: adjust accordingly src/changes.h: src/changes.C: pass Change parameters as const reference git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15366 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/changes.C | 10 +++++----- src/changes.h | 12 ++++++------ src/insets/insettext.C | 3 ++- src/paragraph.C | 20 ++++++++++---------- src/paragraph.h | 16 ++++++++-------- src/paragraph_pimpl.C | 38 +++++++++++++++++++------------------- src/paragraph_pimpl.h | 10 +++++----- 7 files changed, 55 insertions(+), 54 deletions(-) diff --git a/src/changes.C b/src/changes.C index 3d86ce666b..f3173bec95 100644 --- a/src/changes.C +++ b/src/changes.C @@ -96,7 +96,7 @@ Changes::Changes(Changes const & c) } -void Changes::record(Change const change, pos_type const pos) +void Changes::record(Change const & change, pos_type const pos) { if (lyxerr.debugging(Debug::CHANGES)) { lyxerr[Debug::CHANGES] << "record " << change.type @@ -118,7 +118,7 @@ void Changes::record(Change const change, pos_type const pos) } -void Changes::set(Change const change, pos_type const pos) +void Changes::set(Change const & change, pos_type const pos) { set(change, pos, pos + 1); } @@ -137,7 +137,7 @@ void Changes::set(Change::Type const type, } -void Changes::set(Change const change, +void Changes::set(Change const & change, pos_type const start, pos_type const end) { ChangeTable::iterator it = table_.begin(); @@ -254,7 +254,7 @@ void Changes::erase(pos_type const pos) } -void Changes::del(Change const change, ChangeTable::size_type const pos) +void Changes::del(Change const & change, ChangeTable::size_type const pos) { // this case happens when building from .lyx if (table_.empty()) { @@ -283,7 +283,7 @@ void Changes::del(Change const change, ChangeTable::size_type const pos) } -void Changes::add(Change const change, ChangeTable::size_type const pos) +void Changes::add(Change const & change, ChangeTable::size_type const pos) { ChangeTable::iterator it = table_.begin(); ChangeTable::iterator end = table_.end(); diff --git a/src/changes.h b/src/changes.h index 516c9c5269..144a1abce9 100644 --- a/src/changes.h +++ b/src/changes.h @@ -58,7 +58,7 @@ public: } /// set the position to the given change - void set(Change change, lyx::pos_type pos); + void set(Change const & change, lyx::pos_type pos); /// set the position to the given change void set(Change::Type, lyx::pos_type pos); @@ -67,10 +67,10 @@ public: void set(Change::Type, lyx::pos_type start, lyx::pos_type end); /// set the range to the given change - void set(Change, lyx::pos_type start, lyx::pos_type end); + void set(Change const & change, lyx::pos_type start, lyx::pos_type end); /// mark the given change and adjust - void record(Change, lyx::pos_type pos); + void record(Change const & change, lyx::pos_type pos); /// return the change at the given position Change const lookup(lyx::pos_type pos) const; @@ -124,7 +124,7 @@ private: class ChangeRange { public: - ChangeRange(lyx::pos_type s, lyx::pos_type e, Change c) + ChangeRange(lyx::pos_type s, lyx::pos_type e, Change const & c) : range(Range(s, e)), change(c) {} Range range; Change change; @@ -139,10 +139,10 @@ private: Change::Type empty_type_; /// handle a delete, either logical or physical (see erase) - void del(Change change, ChangeTable::size_type pos); + void del(Change const & change, ChangeTable::size_type pos); /// handle an add, adjusting range bounds past it - void add(Change change, ChangeTable::size_type pos); + void add(Change const & change, ChangeTable::size_type pos); /// merge neighbouring ranges, assuming that they are abutting /// (as done by set()) diff --git a/src/insets/insettext.C b/src/insets/insettext.C index a926f31538..7e6449879f 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -115,9 +115,10 @@ void InsetText::init() void InsetText::markErased(bool erased) { + // FIXME: change tracking (MG) ParagraphList & pars = paragraphs(); for_each(pars.begin(), pars.end(), - bind(&Paragraph::markErased, _1, erased)); + bind(&Paragraph::setChange, _1, Change(erased ? Change::DELETED : Change::UNCHANGED))); } diff --git a/src/paragraph.C b/src/paragraph.C index bbb47f5548..62657139d5 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -265,28 +265,28 @@ void Paragraph::insert(pos_type start, string const & str, void Paragraph::insertChar(pos_type pos, Paragraph::value_type c, - Change change) + Change const & change) { pimpl_->insertChar(pos, c, change); } void Paragraph::insertChar(pos_type pos, Paragraph::value_type c, - LyXFont const & font, Change change) + LyXFont const & font, Change const & change) { pimpl_->insertChar(pos, c, change); setFont(pos, font); } -void Paragraph::insertInset(pos_type pos, InsetBase * inset, Change change) +void Paragraph::insertInset(pos_type pos, InsetBase * inset, Change const & change) { pimpl_->insertInset(pos, inset, change); } void Paragraph::insertInset(pos_type pos, InsetBase * inset, - LyXFont const & font, Change change) + LyXFont const & font, Change const & change) { pimpl_->insertInset(pos, inset, change); setFont(pos, font); @@ -1440,21 +1440,21 @@ bool Paragraph::isChangeEdited(pos_type start, pos_type end) const } -void Paragraph::setChangeType(lyx::pos_type pos, Change::Type type) +void Paragraph::setChange(Change const & change) { - pimpl_->setChangeType(pos, type); + pimpl_->setChange(change); } -void Paragraph::setChange(lyx::pos_type pos, Change change) +void Paragraph::setChangeType(lyx::pos_type pos, Change::Type type) { - pimpl_->setChange(pos, change); + pimpl_->setChangeType(pos, type); } -void Paragraph::markErased(bool erased) +void Paragraph::setChange(lyx::pos_type pos, Change const & change) { - pimpl_->markErased(erased); + pimpl_->setChange(pos, change); } diff --git a/src/paragraph.h b/src/paragraph.h index b2b0763dda..b09786d294 100644 --- a/src/paragraph.h +++ b/src/paragraph.h @@ -207,8 +207,11 @@ public: /// set change type at given pos void setChangeType(lyx::pos_type pos, Change::Type type); + /// set change for the entire par + void setChange(Change const & change); + /// set change at given pos - void setChange(lyx::pos_type pos, Change change); + void setChange(lyx::pos_type pos, Change const & change); /// accept change void acceptChange(lyx::pos_type start, lyx::pos_type end); @@ -216,9 +219,6 @@ public: /// reject change void rejectChange(lyx::pos_type start, lyx::pos_type end); - /// mark whole par as erased or not - void markErased(bool erased); - /// Paragraphs can contain "manual labels", for example, Description /// environment. The text for this user-editable label is stored in /// the paragraph alongside the text of the rest of the paragraph @@ -298,16 +298,16 @@ public: void insert(lyx::pos_type pos, std::string const & str, LyXFont const & font); /// - void insertChar(lyx::pos_type pos, value_type c, Change change); + void insertChar(lyx::pos_type pos, value_type c, Change const & change); /// void insertChar(lyx::pos_type pos, value_type c, - LyXFont const &, Change change); + LyXFont const &, Change const & change); /// void insertInset(lyx::pos_type pos, InsetBase * inset, - Change change); + Change const & change); /// void insertInset(lyx::pos_type pos, InsetBase * inset, - LyXFont const &, Change change); + LyXFont const &, Change const & change); /// bool insetAllowed(InsetBase_code code); /// diff --git a/src/paragraph_pimpl.C b/src/paragraph_pimpl.C index bf4ab321f2..795eae90d4 100644 --- a/src/paragraph_pimpl.C +++ b/src/paragraph_pimpl.C @@ -108,6 +108,22 @@ bool Paragraph::Pimpl::isChangeEdited(pos_type start, pos_type end) const } +void Paragraph::Pimpl::setChange(Change const & change) +{ + // FIXME: change tracking (MG) + // changes_.set(change, 0, size()); + + if (change.type == Change::UNCHANGED) { // only for UNCHANGED ??? + for (pos_type i = 0; i < size(); ++i) { + if (owner_->isInset(i)) { + // FIXME: change tracking (MG) + // owner_->getInset(i)->setChange(change); + } + } + } +} + + void Paragraph::Pimpl::setChangeType(pos_type pos, Change::Type type) { if (!tracking()) @@ -117,7 +133,7 @@ void Paragraph::Pimpl::setChangeType(pos_type pos, Change::Type type) } -void Paragraph::Pimpl::setChange(pos_type pos, Change change) +void Paragraph::Pimpl::setChange(pos_type pos, Change const & change) { if (!tracking()) return; @@ -135,22 +151,6 @@ Change const Paragraph::Pimpl::lookupChange(pos_type pos) const } -void Paragraph::Pimpl::markErased(bool erased) -{ - BOOST_ASSERT(tracking()); - - if (erased) { - erase(0, size()); - } else { - for (pos_type i = 0; i < size(); ++i) { - changes_->set(Change::UNCHANGED, i); - if (owner_->isInset(i)) - owner_->getInset(i)->markErased(false); - } - } -} - - void Paragraph::Pimpl::acceptChange(pos_type start, pos_type end) { if (!tracking()) @@ -235,7 +235,7 @@ Paragraph::value_type Paragraph::Pimpl::getChar(pos_type pos) const } -void Paragraph::Pimpl::insertChar(pos_type pos, value_type c, Change change) +void Paragraph::Pimpl::insertChar(pos_type pos, value_type c, Change const & change) { BOOST_ASSERT(pos <= size()); @@ -269,7 +269,7 @@ void Paragraph::Pimpl::insertChar(pos_type pos, value_type c, Change change) void Paragraph::Pimpl::insertInset(pos_type pos, - InsetBase * inset, Change change) + InsetBase * inset, Change const & change) { BOOST_ASSERT(inset); BOOST_ASSERT(pos <= size()); diff --git a/src/paragraph_pimpl.h b/src/paragraph_pimpl.h index 5fe2da5565..7c91142cbe 100644 --- a/src/paragraph_pimpl.h +++ b/src/paragraph_pimpl.h @@ -44,12 +44,12 @@ public: bool isChanged(lyx::pos_type start, lyx::pos_type end) const; /// is there a non-addition in this range ? bool isChangeEdited(lyx::pos_type start, lyx::pos_type end) const; + /// set change for the entire par + void setChange(Change const & change); /// set change type at given pos void setChangeType(lyx::pos_type pos, Change::Type type); /// set change at given pos - void setChange(lyx::pos_type pos, Change change); - /// mark as erased - void markErased(bool); + void setChange(lyx::pos_type pos, Change const & change); /// accept change void acceptChange(lyx::pos_type start, lyx::pos_type end); /// reject change @@ -62,9 +62,9 @@ public: /// void setChar(lyx::pos_type pos, value_type c); /// - void insertChar(lyx::pos_type pos, value_type c, Change change); + void insertChar(lyx::pos_type pos, value_type c, Change const & change); /// - void insertInset(lyx::pos_type pos, InsetBase * inset, Change change); + void insertInset(lyx::pos_type pos, InsetBase * inset, Change const & change); /// definite erase void eraseIntern(lyx::pos_type pos); /// erase the given position. Returns true if it was actually erased -- 2.39.2