mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-25 17:44:59 +00:00
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:
parent
5c44cab01c
commit
717121eba6
@ -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
|
||||||
|
@ -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;
|
||||||
|
|
||||||
@ -62,20 +65,20 @@ textclass_type textclass = 0;
|
|||||||
|
|
||||||
} // namespace anon
|
} // namespace anon
|
||||||
|
|
||||||
PitPosPair CutAndPaste::cutSelection(ParagraphList & pars,
|
PitPosPair CutAndPaste::cutSelection(ParagraphList & pars,
|
||||||
ParagraphList::iterator startpit,
|
ParagraphList::iterator startpit,
|
||||||
ParagraphList::iterator endpit,
|
ParagraphList::iterator endpit,
|
||||||
int startpos, int endpos,
|
int startpos, int endpos,
|
||||||
textclass_type tc, bool doclear)
|
textclass_type tc, bool doclear)
|
||||||
{
|
{
|
||||||
copySelection(startpit, endpit, startpos, endpos, tc);
|
copySelection(startpit, endpit, startpos, endpos, tc);
|
||||||
return eraseSelection(pars, startpit, endpit, startpos,
|
return eraseSelection(pars, startpit, endpit, startpos,
|
||||||
endpos, doclear);
|
endpos, doclear);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PitPosPair CutAndPaste::eraseSelection(ParagraphList & pars,
|
PitPosPair CutAndPaste::eraseSelection(ParagraphList & pars,
|
||||||
ParagraphList::iterator startpit,
|
ParagraphList::iterator startpit,
|
||||||
ParagraphList::iterator endpit,
|
ParagraphList::iterator endpit,
|
||||||
int startpos, int endpos, bool doclear)
|
int startpos, int endpos, bool doclear)
|
||||||
{
|
{
|
||||||
@ -131,7 +134,7 @@ PitPosPair CutAndPaste::eraseSelection(ParagraphList & pars,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// paste the paragraphs again, if possible
|
// paste the paragraphs again, if possible
|
||||||
if (all_erased &&
|
if (all_erased &&
|
||||||
(startpit->hasSameLayout(*boost::next(startpit)) ||
|
(startpit->hasSameLayout(*boost::next(startpit)) ||
|
||||||
boost::next(startpit)->empty())) {
|
boost::next(startpit)->empty())) {
|
||||||
#warning current_view used here.
|
#warning current_view used here.
|
||||||
@ -148,7 +151,18 @@ PitPosPair CutAndPaste::eraseSelection(ParagraphList & pars,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool CutAndPaste::copySelection(ParagraphList::iterator startpit,
|
namespace {
|
||||||
|
|
||||||
|
struct resetOwnerAndChanges {
|
||||||
|
void operator()(Paragraph & p) {
|
||||||
|
p.cleanChanges();
|
||||||
|
p.setInsetOwner(0);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // anon namespace
|
||||||
|
|
||||||
|
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,44 +172,33 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pair<PitPosPair, ParagraphList::iterator>
|
pair<PitPosPair, ParagraphList::iterator>
|
||||||
CutAndPaste::pasteSelection(ParagraphList & pars,
|
CutAndPaste::pasteSelection(ParagraphList & pars,
|
||||||
ParagraphList::iterator pit, int pos,
|
ParagraphList::iterator pit, int pos,
|
||||||
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
|
||||||
@ -280,7 +282,7 @@ CutAndPaste::pasteSelection(ParagraphList & pars,
|
|||||||
// open the paragraph for inserting the buf
|
// open the paragraph for inserting the buf
|
||||||
// if necessary
|
// if necessary
|
||||||
if (pit->size() > pos || !pit->next()) {
|
if (pit->size() > pos || !pit->next()) {
|
||||||
breakParagraphConservative(current_view->buffer()->params,
|
breakParagraphConservative(current_view->buffer()->params,
|
||||||
pars, &*pit, pos);
|
pars, &*pit, pos);
|
||||||
paste_the_end = true;
|
paste_the_end = true;
|
||||||
}
|
}
|
||||||
@ -304,15 +306,15 @@ CutAndPaste::pasteSelection(ParagraphList & pars,
|
|||||||
// maybe some pasting
|
// maybe some pasting
|
||||||
if (boost::next(lastbuffer) != paragraphs.end() && paste_the_end) {
|
if (boost::next(lastbuffer) != paragraphs.end() && paste_the_end) {
|
||||||
if (boost::next(lastbuffer)->hasSameLayout(*lastbuffer)) {
|
if (boost::next(lastbuffer)->hasSameLayout(*lastbuffer)) {
|
||||||
mergeParagraph(current_view->buffer()->params, pars,
|
mergeParagraph(current_view->buffer()->params, pars,
|
||||||
lastbuffer);
|
lastbuffer);
|
||||||
} else if (!boost::next(lastbuffer)->size()) {
|
} else if (!boost::next(lastbuffer)->size()) {
|
||||||
boost::next(lastbuffer)->makeSameLayout(*lastbuffer);
|
boost::next(lastbuffer)->makeSameLayout(*lastbuffer);
|
||||||
mergeParagraph(current_view->buffer()->params, pars,
|
mergeParagraph(current_view->buffer()->params, pars,
|
||||||
lastbuffer);
|
lastbuffer);
|
||||||
} else if (!lastbuffer->size()) {
|
} else if (!lastbuffer->size()) {
|
||||||
lastbuffer->makeSameLayout(*boost::next(lastbuffer));
|
lastbuffer->makeSameLayout(*boost::next(lastbuffer));
|
||||||
mergeParagraph(current_view->buffer()->params, pars,
|
mergeParagraph(current_view->buffer()->params, pars,
|
||||||
lastbuffer);
|
lastbuffer);
|
||||||
} else
|
} else
|
||||||
boost::next(lastbuffer)->stripLeadingSpaces();
|
boost::next(lastbuffer)->stripLeadingSpaces();
|
||||||
@ -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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user