From 408b96bb928c7fcc436f554732e20ef112b5e4b1 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Thu, 16 Jul 2009 08:37:32 +0000 Subject: [PATCH] un-revert r30531, after Richard told me how to avoid the crash. Now, before accepting changes in a clipboard copy (CutAndPaste.cpp), we set the buffer of insets (and we reset them later). Doing this makes sense because we know this is the only operation on these out-of-document paragraphs that will require access to a buffer. Also, this commit gets rid of one explicit test against ERT_CODE and LISTING_CODE. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@30623 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/CutAndPaste.cpp | 31 ++++++++++++++++++++++--------- src/Paragraph.cpp | 12 +++++------- src/Paragraph.h | 4 ++-- src/Text.cpp | 6 +++--- src/insets/Inset.cpp | 2 -- src/insets/Inset.h | 8 ++++---- src/insets/InsetTabular.cpp | 8 ++++---- src/insets/InsetTabular.h | 5 ++--- src/insets/InsetText.cpp | 8 ++++---- src/insets/InsetText.h | 5 ++--- src/paragraph_funcs.cpp | 2 +- 11 files changed, 49 insertions(+), 42 deletions(-) diff --git a/src/CutAndPaste.cpp b/src/CutAndPaste.cpp index 0e81a04b62..91d5321325 100644 --- a/src/CutAndPaste.cpp +++ b/src/CutAndPaste.cpp @@ -456,20 +456,33 @@ void copySelectionHelper(Buffer const & buf, ParagraphList const & pars, ParagraphList::iterator it_end = copy_pars.end(); for (; it != it_end; it++) { - // ERT paragraphs have the Language latex_language. - // This is invalid outside of ERT, so we need to change it - // to the buffer language. - if (it->ownerCode() == ERT_CODE || it->ownerCode() == LISTINGS_CODE) - it->changeLanguage(buf.params(), latex_language, buf.language()); - - it->setInsetOwner(0); + // Since we have a copy of the paragraphs, the insets + // do not have a proper buffer reference. It makes + // sense to add them temporarily, because the + // operations below depend on that (acceptChanges included). + it->setBuffer(const_cast(buf)); + // PassThru paragraphs have the Language + // latex_language. This is invalid for others, so we + // need to change it to the buffer language. + if (it->inInset().getLayout().isPassThru()) + it->changeLanguage(buf.params(), + latex_language, buf.language()); } - // do not copy text (also nested in insets) which is marked as deleted, - // unless the whole selection was deleted + // do not copy text (also nested in insets) which is marked as + // deleted, unless the whole selection was deleted if (!isFullyDeleted(copy_pars)) acceptChanges(copy_pars, buf.params()); + + // do some final cleanup now, to make sure that the paragraphs + // are not linked to something else. + it = copy_pars.begin(); + for (; it != it_end; it++) { + it->setBuffer(*static_cast(0)); + it->setInsetOwner(0); + } + DocumentClass * d = const_cast(dc); cutstack.push(make_pair(copy_pars, d)); } diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp index 5ca9092a4a..c24ec27244 100644 --- a/src/Paragraph.cpp +++ b/src/Paragraph.cpp @@ -362,8 +362,7 @@ Change const & Paragraph::lookupChange(pos_type pos) const } -void Paragraph::acceptChanges(BufferParams const & bparams, pos_type start, - pos_type end) +void Paragraph::acceptChanges(pos_type start, pos_type end) { LASSERT(start >= 0 && start <= size(), /**/); LASSERT(end > start && end <= size() + 1, /**/); @@ -373,14 +372,14 @@ void Paragraph::acceptChanges(BufferParams const & bparams, pos_type start, case Change::UNCHANGED: // accept changes in nested inset if (Inset * inset = getInset(pos)) - inset->acceptChanges(bparams); + inset->acceptChanges(); break; case Change::INSERTED: d->changes_.set(Change(Change::UNCHANGED), pos); // also accept changes in nested inset if (Inset * inset = getInset(pos)) - inset->acceptChanges(bparams); + inset->acceptChanges(); break; case Change::DELETED: @@ -398,8 +397,7 @@ void Paragraph::acceptChanges(BufferParams const & bparams, pos_type start, } -void Paragraph::rejectChanges(BufferParams const & bparams, - pos_type start, pos_type end) +void Paragraph::rejectChanges(pos_type start, pos_type end) { LASSERT(start >= 0 && start <= size(), /**/); LASSERT(end > start && end <= size() + 1, /**/); @@ -409,7 +407,7 @@ void Paragraph::rejectChanges(BufferParams const & bparams, case Change::UNCHANGED: // reject changes in nested inset if (Inset * inset = getInset(pos)) - inset->rejectChanges(bparams); + inset->rejectChanges(); break; case Change::INSERTED: diff --git a/src/Paragraph.h b/src/Paragraph.h index 2423b7492e..e1cb33e0f1 100644 --- a/src/Paragraph.h +++ b/src/Paragraph.h @@ -229,10 +229,10 @@ public: void setChange(pos_type pos, Change const & change); /// accept changes within the given range - void acceptChanges(BufferParams const & bparams, pos_type start, pos_type end); + void acceptChanges(pos_type start, pos_type end); /// reject changes within the given range - void rejectChanges(BufferParams const & bparams, pos_type start, pos_type end); + 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 diff --git a/src/Text.cpp b/src/Text.cpp index 7cc44d9901..dd8dba4370 100644 --- a/src/Text.cpp +++ b/src/Text.cpp @@ -840,9 +840,9 @@ void Text::acceptOrRejectChanges(Cursor & cur, ChangeOp op) pos_type right = (pit == endPit ? endPos : parSize); if (op == ACCEPT) { - pars_[pit].acceptChanges(cur.buffer()->params(), left, right); + pars_[pit].acceptChanges(left, right); } else { - pars_[pit].rejectChanges(cur.buffer()->params(), left, right); + pars_[pit].rejectChanges(left, right); } } @@ -919,7 +919,7 @@ void Text::rejectChanges(BufferParams const & bparams) // (do not consider end-of-par) for (pit_type pit = 0; pit < pars_size; ++pit) { if (!pars_[pit].empty()) // prevent assertion failure - pars_[pit].rejectChanges(bparams, 0, pars_[pit].size()); + pars_[pit].rejectChanges(0, pars_[pit].size()); } // next, reject imaginary end-of-par characters diff --git a/src/insets/Inset.cpp b/src/insets/Inset.cpp index b4ee451e6a..a9c13b76e2 100644 --- a/src/insets/Inset.cpp +++ b/src/insets/Inset.cpp @@ -461,8 +461,6 @@ bool Inset::covers(BufferView const & bv, int x, int y) const InsetLayout const & Inset::getLayout() const { - if (!buffer_) - return DocumentClass::plainInsetLayout(); return buffer().params().documentClass().insetLayout(name()); } diff --git a/src/insets/Inset.h b/src/insets/Inset.h index 3e2cc24314..0f43557991 100644 --- a/src/insets/Inset.h +++ b/src/insets/Inset.h @@ -27,7 +27,6 @@ namespace lyx { class BiblioInfo; class Buffer; -class BufferParams; class BufferView; class Change; class CompletionList; @@ -97,8 +96,9 @@ public: virtual ~Inset() {} /// change associated Buffer - /// FIXME this should go. virtual void setBuffer(Buffer & buffer); + /// remove the buffer reference + void resetBuffer() { setBuffer( *static_cast(0)); } /// retrieve associated Buffer virtual Buffer & buffer(); virtual Buffer const & buffer() const; @@ -487,9 +487,9 @@ public: /// set the change for the entire inset virtual void setChange(Change const &) {} /// accept the changes within the inset - virtual void acceptChanges(BufferParams const &) {}; + virtual void acceptChanges() {}; /// reject the changes within the inset - virtual void rejectChanges(BufferParams const &) {}; + virtual void rejectChanges() {}; /// virtual Dimension const dimension(BufferView const &) const; diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp index e3611d638b..8ebfeb8110 100644 --- a/src/insets/InsetTabular.cpp +++ b/src/insets/InsetTabular.cpp @@ -5152,17 +5152,17 @@ void InsetTabular::setChange(Change const & change) } -void InsetTabular::acceptChanges(BufferParams const & bparams) +void InsetTabular::acceptChanges() { for (idx_type idx = 0; idx < nargs(); ++idx) - cell(idx)->acceptChanges(bparams); + cell(idx)->acceptChanges(); } -void InsetTabular::rejectChanges(BufferParams const & bparams) +void InsetTabular::rejectChanges() { for (idx_type idx = 0; idx < nargs(); ++idx) - cell(idx)->rejectChanges(bparams); + cell(idx)->rejectChanges(); } diff --git a/src/insets/InsetTabular.h b/src/insets/InsetTabular.h index edcc064dd0..9ac05fa489 100644 --- a/src/insets/InsetTabular.h +++ b/src/insets/InsetTabular.h @@ -48,7 +48,6 @@ namespace lyx { class Buffer; -class BufferParams; class BufferView; class CompletionList; class CursorSlice; @@ -803,9 +802,9 @@ public: /// set the change for the entire inset void setChange(Change const & change); /// accept the changes within the inset - void acceptChanges(BufferParams const & bparams); + void acceptChanges(); /// reject the changes within the inset - void rejectChanges(BufferParams const & bparams); + void rejectChanges(); // this should return true if we have a "normal" cell, otherwise false. // "normal" means without width set! diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp index 6184d32eae..8206bd6f25 100644 --- a/src/insets/InsetText.cpp +++ b/src/insets/InsetText.cpp @@ -355,15 +355,15 @@ void InsetText::setChange(Change const & change) } -void InsetText::acceptChanges(BufferParams const & bparams) +void InsetText::acceptChanges() { - text_.acceptChanges(bparams); + text_.acceptChanges(buffer().params()); } -void InsetText::rejectChanges(BufferParams const & bparams) +void InsetText::rejectChanges() { - text_.rejectChanges(bparams); + text_.rejectChanges(buffer().params()); } diff --git a/src/insets/InsetText.h b/src/insets/InsetText.h index e2cbc257c0..063817d2fe 100644 --- a/src/insets/InsetText.h +++ b/src/insets/InsetText.h @@ -21,7 +21,6 @@ namespace lyx { -class BufferParams; class CompletionList; class CursorSlice; class Dimension; @@ -116,9 +115,9 @@ public: /// set the change for the entire inset void setChange(Change const & change); /// accept the changes within the inset - void acceptChanges(BufferParams const & bparams); + void acceptChanges(); /// reject the changes within the inset - void rejectChanges(BufferParams const & bparams); + void rejectChanges(); /// append text onto the existing text void appendParagraphs(ParagraphList &); diff --git a/src/paragraph_funcs.cpp b/src/paragraph_funcs.cpp index 0d626e3d64..d299fc8cdd 100644 --- a/src/paragraph_funcs.cpp +++ b/src/paragraph_funcs.cpp @@ -354,7 +354,7 @@ void acceptChanges(ParagraphList & pars, BufferParams const & bparams) // (do not consider end-of-par) for (pit_type pit = 0; pit < pars_size; ++pit) { if (!pars[pit].empty()) // prevent assertion failure - pars[pit].acceptChanges(bparams, 0, pars[pit].size()); + pars[pit].acceptChanges(0, pars[pit].size()); } // next, accept imaginary end-of-par characters -- 2.39.5