2003-05-01 Lars Gullik Bj�nnes <larsbj@gullik.net>

* CutAndPaste.C (resetOwnerAndChanges): new helper functor
(copySelection): clean up a bit.
(pasteSelection): use make_pair


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6907 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Lars Gullik Bjønnes 2003-05-01 12:53:22 +00:00
parent 5c44cab01c
commit 717121eba6
2 changed files with 42 additions and 37 deletions

View File

@ -1,5 +1,9 @@
2003-05-01 Lars Gullik Bjønnes <larsbj@gullik.net> 2003-05-01 Lars Gullik Bjønnes <larsbj@gullik.net>
* CutAndPaste.C (resetOwnerAndChanges): new helper functor
(copySelection): clean up a bit.
(pasteSelection): use make_pair
* ParagraphList.C (ParagraphList): implement copy constructor * ParagraphList.C (ParagraphList): implement copy constructor
(operator=): implement, base on copy constructor. (operator=): implement, base on copy constructor.
(assign): new func (assign): new func

View File

@ -30,6 +30,9 @@
using std::endl; using std::endl;
using std::pair; using std::pair;
using std::make_pair;
using std::for_each;
using lyx::pos_type; using lyx::pos_type;
using lyx::textclass_type; using lyx::textclass_type;
@ -148,6 +151,17 @@ PitPosPair CutAndPaste::eraseSelection(ParagraphList & pars,
} }
namespace {
struct resetOwnerAndChanges {
void operator()(Paragraph & p) {
p.cleanChanges();
p.setInsetOwner(0);
}
};
} // anon namespace
bool CutAndPaste::copySelection(ParagraphList::iterator startpit, bool CutAndPaste::copySelection(ParagraphList::iterator startpit,
ParagraphList::iterator endpit, ParagraphList::iterator endpit,
int start, int end, textclass_type tc) int start, int end, textclass_type tc)
@ -158,31 +172,21 @@ bool CutAndPaste::copySelection(ParagraphList::iterator startpit,
lyx::Assert(0 <= end && end <= endpit->size()); lyx::Assert(0 <= end && end <= endpit->size());
lyx::Assert(startpit != endpit || start <= end); lyx::Assert(startpit != endpit || start <= end);
paragraphs.clear();
textclass = tc; textclass = tc;
// clone the paragraphs within the selection // Clone the paragraphs within the selection.
ParagraphList::iterator tmppit = startpit;
ParagraphList::iterator postend = boost::next(endpit); ParagraphList::iterator postend = boost::next(endpit);
for (; tmppit != postend; ++tmppit) { paragraphs.assign(startpit, postend);
paragraphs.push_back(new Paragraph(*tmppit, false)); for_each(paragraphs.begin(), paragraphs.end(), resetOwnerAndChanges());
Paragraph & newpar = paragraphs.back();
// reset change info (can these go to the par ctor?)
newpar.cleanChanges();
newpar.setInsetOwner(0);
}
// Cut out the end of the last paragraph. // Cut out the end of the last paragraph.
Paragraph & back = paragraphs.back(); Paragraph & back = paragraphs.back();
for (pos_type tmppos = back.size() - 1; tmppos >= end; --tmppos) back.erase(end, back.size());
back.erase(tmppos);
// Cut out the begin of the first paragraph // Cut out the begin of the first paragraph
Paragraph & front = paragraphs.front(); Paragraph & front = paragraphs.front();
for (pos_type tmppos = start; tmppos; --tmppos) front.erase(0, start);
front.erase(0);
return true; return true;
} }
@ -194,8 +198,7 @@ CutAndPaste::pasteSelection(ParagraphList & pars,
textclass_type tc) textclass_type tc)
{ {
if (!checkPastePossible()) if (!checkPastePossible())
return pair<PitPosPair,ParagraphList::iterator> return make_pair(PitPosPair(pit, pos), pit);
(PitPosPair(pit, pos), pit);
lyx::Assert (pos <= pit->size()); lyx::Assert (pos <= pit->size());
@ -209,8 +212,7 @@ CutAndPaste::pasteSelection(ParagraphList & pars,
} }
#else #else
// Later we want it done like this: // Later we want it done like this:
ParagraphList simple_cut_clone(paragraphs.begin(), ParagraphList simple_cut_clone = paragraphs;
paragraphs.end());
#endif #endif
// now remove all out of the buffer which is NOT allowed in the // now remove all out of the buffer which is NOT allowed in the
// new environment and set also another font if that is required // new environment and set also another font if that is required
@ -320,8 +322,7 @@ CutAndPaste::pasteSelection(ParagraphList & pars,
// restore the simple cut buffer // restore the simple cut buffer
paragraphs = simple_cut_clone; paragraphs = simple_cut_clone;
return pair<PitPosPair,ParagraphList::iterator> (PitPosPair(pit, pos), return make_pair(PitPosPair(pit, pos), endpit);
endpit);
} }