mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-26 14:15:32 +00:00
change tracking:
* 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
This commit is contained in:
parent
fe2abd3846
commit
d53d4a5c35
@ -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; }
|
||||
|
@ -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();
|
||||
|
@ -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!
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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 &);
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
BOOST_ASSERT(start >= 0 && start <= size());
|
||||
BOOST_ASSERT(end > start && end <= size() + 1);
|
||||
|
||||
// care for empty pars
|
||||
|
||||
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))
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user